如何在Delphi中为使用xsd模式的SOAP请求插入值?

时间:2019-01-10 08:55:40

标签: xml delphi soap xsd wsdl

我已经从文件和他的.xsd模式导入了WSDL到Delphi。在这种情况下,我不知道如何向请求中插入值,因为TRemotable类没有私有的,发布的声明都没有Create构造函数。 WSDL使用.xsd模式。当我执行程序时,它正在连接到服务器,我需要确认证书(这是正常的),但是之后我收到错误消息:“输入数据与XML模式定义不匹配”。我认为是因为请求发送时没有输入字符串。 (我曾尝试在SoapUI中发送不带输入字符串的邮件,并收到相同的响应)。 请您解释一下如何使用架构将值插入请求?

我尝试了WSDL如何在SoapUI中工作,并且工作正常,这是测试服务器的简单方法。我写了一个要输入的字符串,并且如果服务器正常工作,则服务器会以响应的方式发送回去。

部分导入的WSDL:

  // ************************************************************************ //
  // XML       : SupportPingRequest, global, <element>
  // Namespace : urn:wsdltypes.nmvs.eu:v2.0
  // Serializtn: [xoLiteralParam]
  // Info      : Wrapper
  // ************************************************************************ //
  SupportPingRequest = class(TRemotable)
  private
  public
    constructor Create; override;
  published
  end;


  // ************************************************************************ //
  // XML       : SupportPingResponse, global, <element>
  // Namespace : urn:wsdltypes.nmvs.eu:v2.0
  // Serializtn: [xoLiteralParam]
  // Info      : Wrapper
  // ************************************************************************ //
  SupportPingResponse = class(TRemotable)
  private
  public
    constructor Create; override;
  published
  end;



  // ************************************************************************ //
  // Namespace : urn:services.nmvs.eu:v2.0
  // soapAction: |urn:PingSupport|urn:G445ChangePassword|urn:G482LoadTC|urn:G483ConfirmTC
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // use       : literal
  // binding   : WSHttpBinding_ISupportServices
  // service   : SupportServices
  // port      : Port_SupportServices
  // URL       : http://localhost:8080/WS_SUPPORT_V1/SupportServiceV10
  // ************************************************************************ //
  ISupportServices = interface(IInvokable)
  ['{A99C22A3-2FE1-EF7A-C0D6-2881F888FE1C}']

    // Cannot unwrap: 
    //     - Input element wrapper name does not match operation's name
    function  PingSupport(const messageParameters: SupportPingRequest): SupportPingResponse; stdcall;

  end;

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

我的代码:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  WS_PKI, WS_SUPPORT;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Service: ISupportServices;
  req: SupportPingRequest;
  res: SupportPingResponse;

begin
  req:= SupportPingRequest.Create;

  try
    GetISupportServices.PingSupport(req);
  finally
    req.Free;
  end;

end;

end.

== EDIT ==

SoapUI请求:(我想在Delphi中插入urn1:Input值)

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:wsdltypes.nmvs.eu:v2.0" xmlns:urn1="urn:types.nmvs.eu:v2.0">
   <soap:Header/>
   <soap:Body>
      <urn:SupportPingRequest>
         <urn1:Input>test string</urn1:Input>
      </urn:SupportPingRequest>
   </soap:Body>
</soap:Envelope>

SoapUI响应:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
   <soap:Body>
      <ns2:SupportPingResponse xmlns:ns1="urn:types.nmvs.eu:v2.0" xmlns:ns2="urn:wsdltypes.nmvs.eu:v2.0">
         <ns1:Output>test string</ns1:Output>
      </ns2:SupportPingResponse>
   </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:0)

最后,Delphi 10.2.3出现问题,错误地导入了WSDL文件,并且缺少了一半的类。我已经升级到10.3,并正确导入了文件。