怎样调用接口里面的函数,在线等(300分)

  • 主题发起人 主题发起人 liangzhang3942
  • 开始时间 开始时间
L

liangzhang3942

Unregistered / Unconfirmed
GUEST, unregistred user!
我想调用接口里面的函数,但是不知道怎样调用,特着急,下面是一个单元的接口函数

unit Service_RySb;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

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"




Service_RysbSoap = interface(IInvokable)
['{189DDA3B-599C-9807-FD08-F30347B43999}']
function F_GetDate: WideString; stdcall;
function F_ZySb(const strZyBlCode: WideString; const strXML: WideString): WideString; stdcall;
end;

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


implementation
上面是单元的声明内容
我想调用的函数是F_ZySb,请问各位老大怎么调用呀
 
var
sr: Service_RysbSoap;
sCode, sXml: WideString;
begin
sr.F_GetDate;
sr.F_ZySb(sCode, sXml);
end;
 
先用GetService_RysbSoap获得一个Service_RysbSoap啊.
 
to总有爱
GetService_RysbSoap获得一个Service_RysbSoap怎么来实现呀,还有lx8598大侠说的根本不行呀
 
改改:

var
sr: Service_RysbSoap;
sCode, sXml: WideString;
begin
sr := GetService_RysbSoap(xxxxxx);
sr.F_GetDate;
sr.F_ZySb(sCode, sXml);
end;
 
先了解一下接口吧。接口只是做的一个类似抽象类中的抽象函数一样的功能,如果没有继承这个接口实现的类,你这个接口是没有任何功能的,也不能随便调用其中的函数的了啊。建议先看看delphi中的接口机制吧。看了你就知道怎么调用了,也知道接口是怎么回事了。
 
function GetService_RysbSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): Service_RysbSoap;
肯定是有个类或这COM实现了这个接口,细节你可以不管,但是这个方法肯定是返回了个接口给你,Passion给的就是实际用法,如果不能用,那肯定是你机器并没有实现这个接口的类或者实现这个接口的COM服务器没有注册或启动
 
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://192.168.2.1/Hzyl_Ts/Service_RySb.asmx?WSDL
// Encoding : utf-8
// Version : 1.0
// (2008-09-13 14:59:56 - 1.33.2.5)
// ************************************************************************ //

unit Service_RySb;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

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"



// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : Service_RysbSoap
// service : Service_Rysb
// port : Service_RysbSoap
// URL : http://192.168.2.1/Hzyl_Ts/Service_RySb.asmx
// ************************************************************************ //
Service_RysbSoap = interface(IInvokable)
['{189DDA3B-599C-9807-FD08-F30347B43999}']
function F_GetDate: WideString; stdcall;
function F_ZySb(const strZyBlCode: WideString; const strXML: WideString): WideString; stdcall;
end;

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


implementation

function GetService_RysbSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): Service_RysbSoap;
const
defWSDL = 'http://192.168.2.1/Hzyl_Ts/Service_RySb.asmx?WSDL';
defURL = 'http://192.168.2.1/Hzyl_Ts/Service_RySb.asmx';
defSvc = 'Service_Rysb';
defPrt = 'Service_RysbSoap';
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 Service_RysbSoap);
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(Service_RysbSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service_RysbSoap), 'http://tempuri.org/%operationName%');

end.
 
多人接受答案了。
 
后退
顶部