我做的例子: 先根據webservice生成一個pas文件; // ************************************************************************ // // The types declared in this file were generated from data read from the // WSDL File described below: // WSDL : http://172.20.100.10/CardID/SearchService.asmx?wsdl // >Import : http://172.20.100.10/CardID/SearchService.asmx?wsdl:0 // Encoding : utf-8 // Version : 1.0 // (2010/6/2 下午 05:00:16 - - $Rev: 10138 $) // ************************************************************************ //unit SearchService;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;const IS_OPTN = $0001; IS_REF = $0080; 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 Borland 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"[Gbl] // !:int - "http://www.w3.org/2001/XMLSchema"[Gbl] // ************************************************************************ // // Namespace : Kevin // soapAction: Kevin/Search // transport : http://schemas.xmlsoap.org/soap/http // style : document // binding : SearchServiceSoap // service : SearchService // port : SearchServiceSoap // URL : http://172.20.100.10/CardID/SearchService.asmx // ************************************************************************ // SearchServiceSoap = interface(IInvokable) ['{F2852AB2-7652-FE23-422C-9219A87AF527}'] function Search(const act: WideString; const isUnicode: Integer; const Cardid: WideString; const Uname: WideString; const opUsrid: WideString; const opUsrnm: WideString ): WideString; stdcall; end;function GetSearchServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): SearchServiceSoap; implementation uses SysUtils;function GetSearchServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): SearchServiceSoap; const defWSDL = 'http://172.20.100.10/CardID/SearchService.asmx?wsdl'; defURL = 'http://172.20.100.10/CardID/SearchService.asmx'; defSvc = 'SearchService'; defPrt = 'SearchServiceSoap'; 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 SearchServiceSoap); 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(SearchServiceSoap), 'Kevin', 'utf-8'); InvRegistry.RegisterDefaultSOAPAction(TypeInfo(SearchServiceSoap), 'Kevin/Search'); InvRegistry.RegisterInvokeOptions(TypeInfo(SearchServiceSoap), ioDocument);end.
先根據webservice生成一個pas文件;
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://172.20.100.10/CardID/SearchService.asmx?wsdl
// >Import : http://172.20.100.10/CardID/SearchService.asmx?wsdl:0
// Encoding : utf-8
// Version : 1.0
// (2010/6/2 下午 05:00:16 - - $Rev: 10138 $)
// ************************************************************************ //unit SearchService;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;const
IS_OPTN = $0001;
IS_REF = $0080;
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 Borland 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"[Gbl]
// !:int - "http://www.w3.org/2001/XMLSchema"[Gbl] // ************************************************************************ //
// Namespace : Kevin
// soapAction: Kevin/Search
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// binding : SearchServiceSoap
// service : SearchService
// port : SearchServiceSoap
// URL : http://172.20.100.10/CardID/SearchService.asmx
// ************************************************************************ //
SearchServiceSoap = interface(IInvokable)
['{F2852AB2-7652-FE23-422C-9219A87AF527}']
function Search(const act: WideString; const isUnicode: Integer; const Cardid: WideString; const Uname: WideString; const opUsrid: WideString; const opUsrnm: WideString
): WideString; stdcall;
end;function GetSearchServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): SearchServiceSoap;
implementation
uses SysUtils;function GetSearchServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): SearchServiceSoap;
const
defWSDL = 'http://172.20.100.10/CardID/SearchService.asmx?wsdl';
defURL = 'http://172.20.100.10/CardID/SearchService.asmx';
defSvc = 'SearchService';
defPrt = 'SearchServiceSoap';
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 SearchServiceSoap);
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(SearchServiceSoap), 'Kevin', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(SearchServiceSoap), 'Kevin/Search');
InvRegistry.RegisterInvokeOptions(TypeInfo(SearchServiceSoap), ioDocument);end.
定義
private
aa:SearchServiceSoap;窗休create時,
aa:=GetSearchServiceSoap(False,'',nil);
使用調用webservice:
寫調用的函數或過程......