0

下面是一个示例 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>

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

这是wsdl文件

塞尔维亚国家银行网络服务

如何使此 Web 服务运行

4

1 回答 1

0

I've modified a function I've used in the past to pass data form ColdFusion to Dynamics GP via soap.

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

I believe I've updated the <cfhttpparam />s necessary for the web service you've linked. I would recommend using a software called SOAP UI to test your connection to the service and SOAP XML body outside of ColdFusion. In my above function, the argument soap would be your saved content "soapBody".

One thing needs to be fixed in your soapBody. The text prior to the start of XML is information regarding data that needs to be in the HTTP header, and I've only seen these values imputed as <cfhttpparam />.

The reason I think you may not be getting the desired 200 response with your above code is that the XML body is incorrectly formatted with the WSDL HTTP header example text. I also did not see the length of the body being declared as well.

While trying to set up your connection try just dumping httpResponse out until you start seeing valid soap responses from the server.

于 2013-06-26T19:41:30.643 回答