如何在soap请求中传递结构数组作为参数?

时间:2015-10-12 13:30:58

标签: xml web-services soap coldfusion wsdl

我正在尝试使用在ColdFusion中创建的SOAP Web服务。 WSDL服务的请求部分如下所示:

<wsdl:message name="submitTicketWithExtraInfoRequest">
<wsdl:part name="sUserLdapAlias" type="xsd:string"></wsdl:part>
<wsdl:part name="sIssueDetails" type="xsd:string"></wsdl:part>
<wsdl:part name="sIssueSummary" type="xsd:string"></wsdl:part>
<wsdl:part name="sDeadlineReason" type="xsd:string"></wsdl:part>
<wsdl:part name="nRelatedTo" type="xsd:string"></wsdl:part>
<wsdl:part name="nPriorityLevel" type="xsd:string"></wsdl:part>
<wsdl:part name="nSegmentid" type="xsd:string"></wsdl:part>
<wsdl:part name="sSubmitterPhone" type="xsd:string"></wsdl:part>
<wsdl:part name="sCC" type="xsd:string"></wsdl:part>
<wsdl:part name="sCoSubmitter" type="xsd:string"></wsdl:part>
<wsdl:part name="sDeadline" type="xsd:string"></wsdl:part>
<wsdl:part name="arURLReference" type="impl:ArrayOf_tns1_URLReference"></wsdl:part>
</wsdl:message>

<complexType name="ArrayOf_tns1_URLReference">
    <complexContent>
         <restriction base="soapenc:Array">
             <attribute ref="soapenc:arrayType" wsdl:arrayType="tns1:URLReference[]"/>
         </restriction>
    </complexContent>
</complexType>

<complexType name="URLReference">
     <sequence>
         <element name="sURLReferenceComment" nillable="true" type="xsd:string"/>
         <element name="sURLReferenceURL" nillable="true" type="xsd:string"/>
     </sequence>
</complexType>

我正在使用SoapUI来生成当前看起来像这样的请求:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://some url/webService/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <int:submitTicketWithExtraInfo soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <sUserLdapAlias xsi:type="xsd:string">?</sUserLdapAlias>
         <sIssueDetails xsi:type="xsd:string">?</sIssueDetails>
         <sIssueSummary xsi:type="xsd:string">?</sIssueSummary>
         <sTroubleshooting xsi:type="xsd:string">?</sTroubleshooting>
         <sDeadlineReason xsi:type="xsd:string">?</sDeadlineReason>
         <nRelatedTo xsi:type="xsd:double">?</nRelatedTo>
         <nPriorityLevel xsi:type="xsd:double">?</nPriorityLevel>
         <nSegmentid xsi:type="xsd:double">?</nSegmentid>
         <sSubmitterPhone xsi:type="xsd:string">?</sSubmitterPhone>
         <sCC xsi:type="xsd:string">?</sCC>
         <sCoSubmitter xsi:type="xsd:string">?</sCoSubmitter>
         <sDeadline xsi:type="xsd:string">?</sDeadline>
         <arURLReference xsi:type="int:ArrayOf_tns1_URLReference" soapenc:arrayType="dat:URLReference[]" xmlns:dat="http://dataservice"/>
      </int:submitTicketWithExtraInfo>
   </soapenv:Body>
</soapenv:Envelope>

对于其他参数,我只需要用实际值替换问号?。问题是我不知道如何在我的请求中传递 arURLReference 参数。从WSDL可以看出它是结构数组。

1 个答案:

答案 0 :(得分:1)

我使用ColdFusion的getSOAPRequest()函数来获取Web服务的请求XML。看起来像这样:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:submitTicketWithExtraInfo soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://some url/webService/">
         <sUserLdapAlias xsi:type="xsd:string">psingh46</sUserLdapAlias>
         <sIssueDetails xsi:type="xsd:string">test ticket submit service with extra info</sIssueDetails>
         <sIssueSummary xsi:type="xsd:string">test ticket submit service with extra info</sIssueSummary>
         <sDeadlineReason xsi:type="xsd:string"/>
         <nRelatedTo xsi:type="xsd:string">45898</nRelatedTo>
         <nPriorityLevel xsi:type="xsd:string">71</nPriorityLevel>
         <nSegmentid xsi:type="xsd:string">18244</nSegmentid>
         <sSubmitterPhone xsi:type="xsd:string"/>
         <sCC xsi:type="xsd:string"/>
         <sCoSubmitter xsi:type="xsd:string"/>
         <sDeadline xsi:type="xsd:string"/>
         <arURLReference soapenc:arrayType="ns2:URLReference[2]" xsi:type="soapenc:Array" xmlns:ns2="http://dataservice" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <arURLReference xsi:type="ns2:URLReference">
               <sURLReferenceComment xsi:type="xsd:string">google link</sURLReferenceComment>
               <sURLReferenceURL xsi:type="xsd:string">http://google.com</sURLReferenceURL>
            </arURLReference>
            <arURLReference xsi:type="ns2:URLReference">
               <sURLReferenceComment xsi:type="xsd:string">so link</sURLReferenceComment>
               <sURLReferenceURL xsi:type="xsd:string">http://so.com</sURLReferenceURL>
            </arURLReference>
         </arURLReference>
      </ns1:submitTicketWithExtraInfo>
   </soapenv:Body>
</soapenv:Envelope>

使用上述请求XML,使用SoapUI成功调用该服务。 有关getSOAPRequest()函数的更多信息,请参阅此处。 http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6ca2.html