本文介绍了使用具有复杂类型的SOAP Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to ColdFusion and need to write code to consume a SOAP based web service.

任何用于使用基于SOAP的Web服务的链接/指针/

Any links/pointers/examples for consuming SOAP based web service which has complex types will help.

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

When I am writing the code to consume the below web service in ColdFusion, how should I handle operation name, input msg, and complex types? Just need some pointers to get started.

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


推荐答案

您尚未分享完整的验证码,

You have not shared complete code so some assumptions must be made.

Ben Nadel写了一篇关于这个话题的文章。您应该首先阅读这个:

Ben Nadel has a wonderful write up on this topic. You should definitely read this first: Making SOAP Web Service Requests With ColdFusion And CFHTTP

每当我与SOAP服务交互时,我通常最终使用类似以下内容。它非常类似于您共享的代码片段,但是您没有显示()包含在< cfsavecontent> 标签中的内容,以将XML存储在< cfhttp> 请求之前创建 soap 这可能是你的问题?以下是一个让你去的例子。

Whenever I interact with SOAP services I usually end up using something similar to the following. It is very similar to the code fragment that you shared but you did not show (among other things) the content being wrapped in <cfsavecontent> tags to store the XML in the soap variable before making the <cfhttp> request. This could be your problem? The following is just an example to get you going.

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

使用Web服务时的另一个非常有用的工具是。这肯定是你的工具包的一部分。您可以使用soapUI构建您的请求并检查响应。一旦你使用soapUI,你可以复制你的请求到你的ColdFusion代码。

Another invaluable tool when working with web services is soapUI. That should definitely be a part of your toolkit as well. You can build your request using soapUI and check the responses. Once you have it working with soapUI you can copy your request into your ColdFusion code.

这篇关于使用具有复杂类型的SOAP Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:40