读取从WSDL接口文件生成的soap xml

时间:2016-02-12 12:26:41

标签: xml delphi soap delphi-xe

我在Delphi中创建了半个SOAP接口,试图理解它是如何工作的。我希望看到写出的文件生成的XML,但是作为XML中的newbe,我不知道如何获得它。我已经帮助在服务器端获取它,但我希望能够检查它而无需在服务器中为每个接口设置代码。

以下是代码:

interface

uses Soap.InvokeRegistry, Soap.SOAPHTTPClient, System.Types, Soap.XSBuiltIns;

type

  IHello = interface(IInvokable)
  ['{243CBD89-8766-F19D-38DF-427D7A02EAEE}']
    function  sayHello(const firstName: string): string; stdcall;
  end;

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


implementation
  uses System.SysUtils;

function GetIHello(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IHello;
const
  defWSDL = 'http://localhost:8080/wsdl/IHello';
  defURL  = 'http://localhost:8080/soap/IHello';
  defSvc  = 'IHelloservice';
  defPrt  = 'IHelloPort';
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 IHello);
    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
  { Hello_PortType }
  InvRegistry.RegisterInterface(TypeInfo(IHello), 'Ihelloservice', '');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(IHello), 'sayHello');

end.

0 个答案:

没有答案