首页 > 解决方案 > Delphi SOAP 请求

问题描述

我正在尝试向 Delphi XE5 中的 Web 服务发送 SOAP 请求。实际上,我通过 WSDL Importer 导入了一个可用的 WSDL。我使用组件 THTTPRIO (rio) 和 IdEncoderMIME1 为 HTTP 身份验证请求建立了与此 Web 服务的连接。

SOAP 请求是通过 TXMLDocument 构建的,具有以下结构:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cod=NS_Codelist>
   <soapenv:Header/>
   <soapenv:Body>
      <cod:GetLatestChangeDatesRequest>
         <!--Zero or more repetitions:-->
         <CodeListID>1035</CodeListID>
      </cod:GetLatestChangeDatesRequest>
   </soapenv:Body>
</soapenv:Envelope>

此外,我收到了网络服务的端口类型。

codeserv:= GetCodeListPortType(true,'',rio);

这些是来自 WSDL 的方法:

codeserv.GetLatestChangeDates(const body:GetLatestChangeDatesRequestType):GetLatestChangeDatesResponseType

GetLatestChangeDatesRequestType = array of Int64;  
GetLatestChangeDatesRequest = GetLatestChangeDatesRequestType;

GetLatestChangeDatesResponseType = array of CodeListLatestChangeDateType;   
GetLatestChangeDatesResponse = GetLatestChangeDatesResponseType;

CodeListLatestChangeDateType 
property CodeListID: Int64
property LatestChangeDate: TXSDate

我已经尝试为参数设置一个 Int64 数组,但随后显示“缺少元素 CodeListID”。

不幸的是,我找不到将此 XML SOAP 请求发送到 web 服务并接收响应的方法。有任何想法吗?

编辑:我尝试使用 WSDL 方法

var
    codeserv: CodeListPortType;
    arrIDs: GetLatestChangeDatesRequest;
    response: GetLatestChangeDatesResponse;

   begin
    codeserv:= GetCodeListPortType(true,'',rio);
    SetLength(arrIDs,1);
    arrIDs[0]:= 1035;
    response:= codeserv.GetLatestChangeDates(arrIDs);

但随后我收到以下错误消息:'发现以元素'long'开头的无效内容。需要“{CodeListID}”之一。在 SOAP 请求中必须有元素 CodeListID。不幸的是,GetLatestChangeDates 方法似乎没有在 SOAP 请求中创建元素。上面发布的 SOAP 请求应该是用这种方法创建的(希望如此)。

标签: web-servicesdelphisoap

解决方案


推荐阅读