试图使用ColdFusion消费SOAP API时遇到困难 [英] Stumped with trying to consume a SOAP API using ColdFusion

查看:230
本文介绍了试图使用ColdFusion消费SOAP API时遇到困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的API有两种不同的网址,用于特定类型的功能。第一个是支持JSON或SOAP请求的事务API。我已经使用专有的JSON调用调用了这个API中的所有函数,一切看起来都很完美。

I am working with an API that has two different URLs for specific types of functions. The first, is a transactional API that supports either JSON or SOAP requests. I have called all of the functions I need within this API using exclusively JSON calls and everything appears to be working perfectly fine.

第二种是一种报告API,用于定位和/或下载报告。此API仅与SOAP一起使用。我没有能够得到任何功能在这个API工作正常。我试图联系公司的支持组,但他们没有任何人谁可以帮助我在ColdFusion的API调用。我已经尝试两种不同的方式来与这个API接口,并获得访问的功能,并出现了空。以下是我的例子和尽可能多的信息,我可以提供;我们的服务提供商的API和相关文档是自信的,但我可以回答一些与我的代码有关的具体事情的问题。

The second is a reporting API used to locate and/or download reports. This API works exclusively with SOAP. I have not been able to get any function in this API working properly. I have attempted to contact the company's support group, but they do not have anybody who can assist me with API calls in ColdFusion. I have attempted two different ways to interface with this API and get access to the functions and have come up empty. Below are my examples and as much information as I can provide; our service provider's API and associated documentation are confidental, but I can answer some questions related to specific things that have to do with my code.

方法1:创建一个webservice对象。

Way 1: Creating a webservice object.

我试图创建这个SOAP调用的第一种方法是通过webservice对象。使用元数据交换点URL,我将其传递给createObject函数,如下所示:

The first way I tried to create this SOAP call was through a webservice object. Using the metadata exchange point URL, I passed it into the createObject function like this:

<cfset argStruct = structNew() />
<cfset argStruct['username'] = 'myusername' />
<cfset argStruct['password'] = 'mypassword' />
<cfset testSvc = createObject('webservice','https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex',argStruct) />

当我运行这个代码,我得到以下错误信息:

When I run this code, I get the following error message:


无法为Web服务调用生成存根对象。名称: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc / mex 。 WSDL: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc / mex 。 javax.wsdl.WSDLException:WSDLException(at / wsdl:definitions / wsdl:import):faultCode = OTHER_ERROR:无法解析导入的文档在https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex? wesdl = wsdl1',相对于'brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/':java.io.IOException:服务器返回HTTP响应代码:401 for URL: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1 < a>

Cannot generate stub objects for web service invocation. Name: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex. WSDL: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex. javax.wsdl.WSDLException: WSDLException (at /wsdl:definitions/wsdl:import): faultCode=OTHER_ERROR: Unable to resolve imported document at 'https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1', relative to 'brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/': java.io.IOException: Server returned HTTP response code: 401 for URL: https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1

由于401错误通常是错误的授权,我通过直接在浏览器中调用URL来复核地址,被联合国/ PW提示。我输入了我的值,并允许访问URL,接收这个XML返回:

Since 401 errors are typically bad authorizations, I double-checked the address by calling the URL directly in the browser, where I was prompted with a UN/PW. I entered in my values, and was allowed to access the URL, recieving this XML in return:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="ReportingAPI" targetNamespace="https://https://brandnameapi.serviceprovider.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:tns="https://https://brandnameapi.serviceprovider.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:i0="https://https://brandnameapi.serviceprovider.com/ReportingAPI/soapBinding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<wsdl:import namespace="https://https://brandnameapi.serviceprovider.com/ReportingAPI/soapBinding" location="https://https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1"/>
<wsdl:types/>
<wsdl:service name="ReportingAPI">
    <wsdl:port name="BasicHttpBinding_IReportingAPI" binding="i0:BasicHttpBinding_IReportingAPI">
        <soap:address location="https://https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/soap"/>
    </wsdl:port>
</wsdl:service>

我已经。当我使用我的浏览器调用URL并传递验证信息时,我被允许访问XML。当我尝试使用ColdFusion时,会出现401错误。

This is about as far as I've gotten. When I call the URL with my browser and pass the authentication information, I'm allowed to access the XML. When I try to do so with ColdFusion, I get 401 errors.

方法2:cfhttp请求调用

Way 2: cfhttp request calls

当我切换到使用cfhttp,我似乎得到一点进一步。当我使用这个:

When I switched to using cfhttp, I seemed to get a little further. When I use this:

<cfhttp url="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex"
username="myusername" password="mypassword" method="get" result="httpResponse" 
timeout="300">
</cfhttp>

httpResponse返回相应的页面信息,httpResponse.filecontent返回与我直接调用时相同的XML

httpResponse return appropriate page information, and httpResponse.filecontent returns the same XML I recieved when I called it directly in my browser.

进一步,我使用了SOAP URL并尝试调用API中的一个函数,该函数返回一个可用的报告文件列表。我使用了我在事务API中的所有JSON调用使用的相同的已知工作过程:

Going one step further, I took the SOAP URL and attempted to call a function in the API that returns a list of available report files. I used the same known-working process I used for all of my JSON calls in the transaction API:

<cfhttp url="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/soap/queryAvailableReportFiles"
username="myusername" password="mypassword" method="post" 
result="httpResponse" timeout="300">
<cfhttpparam type="formfield" name="typeOfReport" value="DailyCSVFile" />
</cfhttp>

当我运行此代码时,我获得状态代码415,错误为无法处理消息,因为内容类型application / x-www-form-urlencoded不是预期类型multipart / related; type =application / xop + xml'

When I run this code, I get a status code of 415 and an error of, 'Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'multipart/related; type="application/xop+xml"'

当我在我的cfhttps之间添加此行时:

When I add this line between my cfhttps:

<cfhttpparam type="header" name="Content-Type" value='multipart/related; type="application/xop+xml"' />

我得到与上面相同的错误,但状态代码更改为400。我试图做的一切,只有我现在在那里。

I get the same error as directly above, but the status code changes to 400. I have not included everything I've tried to do, only where I'm at right now. I will answer as many questions as I can and will reperform steps as directed to find a solution to this problem.

更新:根据要求,我们可以根据需要,我改变了cfhttp调用以尝试传递XML而不是表单字段。我的XML代码直接从API文档中剥离,API文档中有来自API的针对不同功能的请求的原始数据示例:

Update: As requested, I have changed the cfhttp call to attempt to pass XML instead of a form field. My XML code is ripped directly from the API documentation that has an example of a raw data for a request from the API for a different function:

<cfsavecontent variable="soapBody">
<cfoutput>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Body>
            <queryAvailableReportFiles
xmlns="https://brandnameapi.sandbox.serviceprovider.com/contract">
                <fileName>DailyCSVFile</fileName>
            </queryAvailableReportFiles>
        </s:Body>
    </s:Envelope>
</cfoutput>
</cfsavecontent>

<cfhttp url="https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles" username="vfapi" password="bPzqQyK3" method="post" result="httpResponse" timeout="300">
<cfhttpparam type="xml" value="#trim(soapBody)#" />
</cfhttp>

为了公平,我不知道我是否这样做。从其返回的错误消息是带有到 https:/ /prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles 无法在接收方处理,因为EndpointDispatcher的AddressFilter不匹配。检查发送方和接收方的EndpointAddresses是否同意。我也得到一个500错误。

To be fair, I have no idea if I'm doing that right. The error message that returns from it is, "The message with To https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree." I also get a 500 error.

推荐答案

他们的API有一个问题。没有代码更改会解决此问题。

There was a problem with their API. No code change would have addressed this issue.

这篇关于试图使用ColdFusion消费SOAP API时遇到困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆