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

Web services 使用具有复杂类型的SOAP web服务,web-services,soap,coldfusion,wsdl,Web Services,Soap,Coldfusion,Wsdl,我是ColdFusion新手,需要编写代码来使用基于SOAP的web服务 任何用于使用具有复杂类型的基于SOAP的web服务的链接/指针/示例都会有所帮助 当我在ColdFusion中编写代码来使用下面的web服务时,我应该如何处理操作名、输入消息和复杂类型?只需要一些指针就可以开始了 XSD类似于: <!-- S Request --> <xs:complexType name="SRequestHeader"> + <xs:sequence&

我是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>

-    
message=“W:newOrderResponse”name=“newOrderResponse”/>
message=“WL:WSException”name=“WSException”/>
我使用的是类似于:

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

S123。。。。
最后

<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)#">

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

本·纳德尔在这个话题上写了一篇精彩的文章。你一定要先读一读:

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

<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" ?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <ns1:newOrder xmlns:ns1="urn:TripFlow" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <sID>001</sID>
         <orderNumber>12345</orderNumber>
         <dateCreated>07/31/2013</dateCreated>
      </ns1:newOrder>
   </soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>

<!--- Invoke web service to send message--->
<cfhttp url="http://xxxx:123/YYY/SService" method="post" timeout="10">
<cfhttpparam type="header" name="content-type" value="text/xml" />
<cfhttpparam type="header" name="SOAPAction" value="""SService-method-name-here""" />
<!---<cfhttpparam type="header" name="accept-encoding" value="no-compression" />  sometimes this is needed --->
<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> 

001
12345
07/31/2013

在使用web服务时,另一个非常宝贵的工具是。这当然也应该是你工具包的一部分。您可以使用soapUI构建请求并检查响应。一旦使用了soapUI,您就可以将请求复制到ColdFusion代码中。

谢谢@Miguel-F。最终使用了soapUI并了解了问题所在

已设置参数throwonerror=“Yes”。因此,ParseException将进入错误块,而不是在代码中捕获


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

指针编号1-您可能需要创建一个对象。有一个标记和一个函数CreateObject()允许您执行此操作。用谷歌搜索每一个,然后决定你想用哪一个。我更喜欢后者。@DanBracuk我使用的是:S123…嗨,我使用的是准确的代码..就像你添加的..但是得到500个内部服务器错误。你知道会出什么问题吗?你是在响应中得到500个错误还是从你的ColdFusion服务器发出请求?尝试使用SoapUI发出SOAP请求,看看是否有效。检查ColdFusion日志以了解有关错误的更多详细信息(如果是在服务器上生成的)。工作正常。非常感谢。我发现SoapUI(和其他类似的工具)在使用web服务时非常宝贵。很高兴你让它工作了。