garfieldtom 发表于 2012-12-10 13:14:44

Delphi调用Java WebService

Delphi调用Java WebService

<div id="cnblogs_post_body">刚用Java做了个WebService,并且在Java中调用成功, WebService在Delphi中同样可以调用。
在Delphi中新建一个工程,然后点击Component->Import WSDL...
http://images.cnblogs.com/cnblogs_com/garfieldtom/importwsdl.png
WSDL的URL以及该WebService的内容请参考:
http://www.cnblogs.com/GarfieldTom/archive/2012/09/14/2684361.html

使用缺省设置,生成引用文件:

<div class="cnblogs_code">// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL   : http://localhost:8030/garfield.MyJ6WebService?wsdl
//>Import : http://localhost:8030/garfield.MyJ6WebService?wsdl>0
//>Import : http://localhost:8030/garfield.MyJ6WebService?xsd=1
// Encoding : UTF-8
// Version: 1.0
// (2012-09-14 9:39:27 - - $Rev: 25127 $)
// ************************************************************************ //

unit garfield;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

const
IS_OPTN = $0001;
IS_UNQL = $0008;


type

// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Embarcadero types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string          - "http://www.w3.org/2001/XMLSchema"



// ************************************************************************ //
// Namespace : http://garfield/
// transport : http://schemas.xmlsoap.org/soap/http
// style   : document
// binding   : MyJ6WebServicePortBinding
// service   : MyJ6WebServiceService
// port      : MyJ6WebServicePort
// URL       : http://localhost:8030/garfield.MyJ6WebService
// ************************************************************************ //


MyJ6WebService = interface(IInvokable)
['{73C2D68E-4BCE-E05A-3459-8E5DFD772DC1}']
    functionSayHello(const arg0: string): string; stdcall;
end;

function GetMyJ6WebService(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): MyJ6WebService;


implementation
uses SysUtils;

function GetMyJ6WebService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): MyJ6WebService;
const
defWSDL = 'http://localhost:8030/garfield.MyJ6WebService?wsdl';
defURL= 'http://localhost:8030/garfield.MyJ6WebService';
defSvc= 'MyJ6WebServiceService';
defPrt= 'MyJ6WebServicePort';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
end;
if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
else
    RIO := HTTPRIO;
try
    Result := (RIO as MyJ6WebService);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
end;
end;


initialization
InvRegistry.RegisterInterface(TypeInfo(MyJ6WebService), 'http://garfield/', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(MyJ6WebService), '');
页: [1]
查看完整版本: Delphi调用Java WebService