你先定义这样一个单元:
unit GetConnStr;//单元的名称你定
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;
type
Service1Soap = interface(IInvokable)
['{CFE467D4-A39E-2BD2-5836-7685A9E27F8D}']
function getConn(const key: WideString): WideString; stdcall; //你要改的就是这些函数,WebService中有什么就写什么。
end;
function GetService1Soap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): Service1Soap;
implementation
function GetService1Soap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): Service1Soap;
const
defWSDL = 'http://localhost/mta/MyService.asmx?wsdl';//这个要不要无所谓,反正可以传入地址
defURL = 'http://localhost/mta/MyService.asmx';
defSvc = 'Service1';
defPrt = 'Service1Soap';
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 Service1Soap);
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(Service1Soap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), 'http://tempuri.org/%operationName%');
InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument);
end.
//注 这个单元可以由Delphi 7.0自己生成。