使用具有复杂类型的SOAP Web服务

时间:2013-07-31 09:57:24

标签: web-services soap coldfusion wsdl

我是ColdFusion的新手,需要编写代码来使用基于SOAP的Web服务。

使用具有复杂类型的基于SOAP的Web服务的任何链接/指针/示例都会有所帮助。

当我编写代码以在ColdFusion中使用以下Web服务时,我应该如何处理操作名称,输入消息和复杂类型?需要一些指导才能开始。

XSD就像:

<!--  S Request -->
    <xs:complexType name="SRequestHeader">
     + <xs:sequence>
     + <xs:element name="sID" minOccurs="1" maxOccurs="1">   </xs:element>
     + <xs:element name="orderNumber" minOccurs="1" maxOccurs="1">   </xs:element>
     + <xs:element name="dateCreated" minOccurs="1" maxOccurs="1">   </xs:element>
    </xs:complexType>
  - <xs:complexType name="SOrderLine">
     - <xs:sequence>
     - <xs:element name="lineNumber" minOccurs="1" maxOccurs="1">   </xs:element>
     - <xs:element name="recordType" minOccurs="1" maxOccurs="1">   </xs:element>
     - <xs:element name="dueDate" minOccurs="1" type="xs:dateTime" />       
    </xs:complexType>
......

WSDL有:

<WL:portType name="SPortType">
- <WL:operation name="newOrder">   
    <WL:input message="WL:newOrderRequest" name="newOrderRequest" />    
    <WL:output> message="W:newOrderResponse" name="newOrderResponse" />    
    <WL:fault> message="WL:WSException" name="WSException" />    
  </WL:operation>

我使用的是:

<soapenv:Body>    
  <newOrder>
  <soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
      <sor:newOrderRequest>
         <sor:SOrderRequest>
            <sor:sID>S123</sor:sID> ....

最后......

<cfhttp url="http://xxxx:123/YYY/SService" method="post" timeout="118"        
       throwonerror="yes">
    <cfhttpparam type="header" name="content-type" value="text/xml">
    <cfhttpparam type="header" name="SOAPAction" value="">
    <cfhttpparam type="header" name="content-length" value="#len(soap)#">
    <cfhttpparam type="header" name="charset" value="utf-8">
    <cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>

在此行中获取 500内部服务器错误

<cfhttpparam type="xml" name="message" value="#trim(soap)#">

2 个答案:

答案 0 :(得分:2)

您尚未共享完整代码,因此必须做出一些假设。

本·纳德尔(Ben Nadel)就这一主题发表了精彩的文章。你一定要先阅读这个:Making SOAP Web Service Requests With ColdFusion And CFHTTP

每当我与SOAP服务交互时,我通常最终会使用类似于以下内容的东西。它与您共享的代码片段非常相似,但您没有显示(除其他外)包含在<cfsavecontent>标记中的内容,以便在创建{{1}之前将XML存储在soap变量中请求。这可能是你的问题?以下只是一个让你前进的例子。

<cfhttp>

使用Web服务时,另一个宝贵的工具是soapUI。这绝对应该是您的工具包的一部分。您可以使用soapUI构建请求并检查响应。使用soapUI后,您可以将请求复制到ColdFusion代码中。

答案 1 :(得分:0)

谢谢@ Miguel-F .FFally used SOAPUI并理解出了什么问题。

设置参数throwonerror =“是”。因为这个ParseException导致错误阻止而不是在代码中捕获。

在设置throwonerror =“No”时,代码最终开始工作并读取响应标记。

相关问题