ColdFusion肥皂客户端

时间:2013-06-24 14:08:54

标签: web-services coldfusion wsdl

以下是SOAP 1.2请求和响应示例。显示的占位符需要替换为实际值。

POST /CommunicationOfficeService1_0/CompanyAccountXmlService.asmx HTTP/1.1
Host: webservices.nbs.rs
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthenticationHeader xmlns="http://communicationoffice.nbs.rs">
      <UserName>string</UserName>
      <Password>string</Password>
      <LicenceID>guid</LicenceID>
    </AuthenticationHeader>
  </soap12:Header>
  <soap12:Body>
    <GetCompanyAccountByNationalIdentificationNumber xmlns="http://communicationoffice.nbs.rs">
      <nationalIdentificationNumber>long</nationalIdentificationNumber>
    </GetCompanyAccountByNationalIdentificationNumber>
  </soap12:Body>
</soap12:Envelope>

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetCompanyAccountByNationalIdentificationNumberResponse xmlns="http://communicationoffice.nbs.rs">
      <GetCompanyAccountByNationalIdentificationNumberResult>string</GetCompanyAccountByNationalIdentificationNumberResult>
    </GetCompanyAccountByNationalIdentificationNumberResponse>
  </soap12:Body>
</soap12:Envelope>

我已经生成了类似这样的ColdFusion代码

<cfsavecontent variable="soapBody">
<cfoutput>

POST /CommunicationOfficeService1_0/CompanyAccountXmlService.asmx HTTP/1.1
Host: webservices.nbs.rs
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthenticationHeader xmlns="http://communicationoffice.nbs.rs">
      <UserName>my_username</UserName>
      <Password>my_password</Password>
      <LicenceID>My_licence_id</LicenceID>
    </AuthenticationHeader>
  </soap12:Header>
  <soap12:Body>
    <GetCompanyAccountByNationalIdentificationNumber xmlns="http://communicationoffice.nbs.rs">
      <nationalIdentificationNumber>20774550</nationalIdentificationNumber>
    </GetCompanyAccountByNationalIdentificationNumber>
  </soap12:Body>
</soap12:Envelope>
</cfoutput>
</cfsavecontent>



<!---
Now that we have our SOAP body defined, we need to post it as
a SOAP request to the Campaign Monitor website. Notice that
when I POST the SOAP request, I am NOT required to append the
"WSDL" flag to the target URL (this is only required when you
actually want to get the web service definition).
--->
<cfhttp
url="https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx"
method="post"
result="httpResponse">

<!---
Most SOAP action require some sort of SOAP Action header
to be used.
--->
<cfhttpparam
type="header"
name="SOAPAction"
value="http://communicationoffice.nbs.rs/GetCompanyAccountByNationalIdentificationNumber"
/>

<!---
I typically use this header because CHTTP cannot handle
GZIP encoding. This "no-compression" directive tells the
server not to pass back GZIPed content.
--->
<cfhttpparam
type="header"
name="accept-encoding"
value="no-compression"

/>

<!---
When posting the SOAP body, I use the CFHTTPParam type of
XML. This does two things: it posts the XML as a the BODY
and sets the mime-type to be XML.

NOTE: Be sure to Trim() your XML since XML data cannot be
parsed with leading whitespace.
--->
<cfhttpparam
type="xml"
value="#trim( soapBody )#"
/>

</cfhttp>


<!---
When the HTTP response comes back, our SOAP response will be
in the FileContent atribute. SOAP always returns valid XML,
even if there was an error (assuming the error was NOT in the
communication, but rather in the data).
--->
<cfif find( "200", httpResponse.statusCode )>

<!--- Parse the XML SOAP response. --->
<cfset soapResponse = xmlParse( httpResponse.fileContent ) />

<!---
Query for the response nodes using XPath. Because the
SOAP XML document has name spaces, querying the document
becomes a little funky. Rather than accessing the node
name directly, we have to use its local-name().
--->
<cfset responseNodes = xmlSearch(
soapResponse,
"//*[ local-name() = 'Subscriber.AddAndResubscribeResult' ]"
) />

<!---
Once we have the response node, we can use our typical
ColdFusion struct-style XML node access.
--->
<cfoutput>

Code: #responseNodes[ 1 ].Code.xmlText#
<br />
Success: #responseNodes[ 1 ].Message.xmlText#

</cfoutput>

</cfif>

我没有结果。 Web服务使用这是网站

这是wsdl文件

Serbian National Bank Web Service

如何运行此Web服务

1 个答案:

答案 0 :(得分:0)

我修改了过去用过的函数,通过soap将数据从ColdFusion传递给Dynamics GP。

<cffunction name="callWebService" access="public" output="false">
    <cfargument name="soap" type="xml" required="true">
    <cfhttp url="https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx"  method="post">
        <cfhttpparam type="header" name="content-type" value="application/soap+xml">
        <cfhttpparam type="header" name="SOAPAction" value="http://communicationoffice.nbs.rs/GetCompanyAccountByNationalIdentificationNumber">
        <cfhttpparam type="header" name="accept-encoding" value="no-compression">
        <cfhttpparam type="header" name="content-length" value="#len(Arguments.soap)#">
        <cfhttpparam type="header" name="charset" value="utf-8">
        <cfhttpparam type="xml" name="message" value="#trim(Arguments.soap)#">
    </cfhttp>
    <cfreturn Trim(cfhttp.FileContent)>
</cffunction>

我相信我已更新您已关联的网络服务所需的<cfhttpparam />s。我建议使用名为SOAP UI的软件来测试与ColdFusion之外的服务和SOAP XML主体的连接。在我的上面的函数中,参数soap将是你保存的内容“soapBody”。

需要在soapBody中修复一件事。 XML开始之前的文本是有关需要在HTTP标头中的数据的信息,我只看到这些值被估算为<cfhttpparam />

我认为您可能无法使用上述代码获得所需的200响应的原因是XML主体使用WSDL HTTP标头示例文本格式不正确。我也没有看到身体的长度也被宣布。

尝试设置连接时,只需将httpResponse转储出去,直到您开始看到来自服务器的有效soap响应。