2013-06-24 255 views
0

以下是示例SOAP 1.2请求和响应。显示的占位符需要用实际值替换。ColdFusion soap客户端

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服务运行

+0

你没有得到任何结果或错误?如果你没有收到错误,你可能连接成功。 –

+0

我没有得到任何结果,奇怪的是,这个Web服务很容易使用从C锐利和PHP,但Java - 无法使用NetBeans向导生成所有正确的类和冷聚变给我什么都没有回来。该网站和Web服务是在ASP技术。可能我错过了一些东西... –

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

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

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

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

尝试设置连接时,尝试将httpResponse输出,直到您开始看到来自服务器的有效肥皂响应。

+0

谢谢我会试一试! –