Note that there are some explanatory texts on larger screens.

plurals
  1. POStumped with trying to consume a SOAP API using ColdFusion
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Way 1: Creating a webservice object.</p> <p>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:</p> <pre><code>&lt;cfset argStruct = structNew() /&gt; &lt;cfset argStruct['username'] = 'myusername' /&gt; &lt;cfset argStruct['password'] = 'mypassword' /&gt; &lt;cfset testSvc = createObject('webservice','https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex',argStruct) /&gt; </code></pre> <p>When I run this code, I get the following error message:</p> <blockquote> <p>Cannot generate stub objects for web service invocation. Name: <a href="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex" rel="nofollow">https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex</a>. WSDL: <a href="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex" rel="nofollow">https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex</a>. 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: <a href="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1" rel="nofollow">https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1</a></p> </blockquote> <p>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:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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/"&gt; &lt;wsdl:import namespace="https://https://brandnameapi.serviceprovider.com/ReportingAPI/soapBinding" location="https://https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex?wsdl=wsdl1"/&gt; &lt;wsdl:types/&gt; &lt;wsdl:service name="ReportingAPI"&gt; &lt;wsdl:port name="BasicHttpBinding_IReportingAPI" binding="i0:BasicHttpBinding_IReportingAPI"&gt; &lt;soap:address location="https://https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/soap"/&gt; &lt;/wsdl:port&gt; &lt;/wsdl:service&gt; </code></pre> <p></p> <p>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.</p> <p>Way 2: cfhttp request calls</p> <p>When I switched to using cfhttp, I seemed to get a little further. When I use this:</p> <pre><code>&lt;cfhttp url="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/mex" username="myusername" password="mypassword" method="get" result="httpResponse" timeout="300"&gt; &lt;/cfhttp&gt; </code></pre> <p>httpResponse return appropriate page information, and httpResponse.filecontent returns the same XML I recieved when I called it directly in my browser.</p> <p>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:</p> <pre><code>&lt;cfhttp url="https://brandnameapi.sandbox.serviceprovider.com/vernum/ReportingAPI.svc/soap/queryAvailableReportFiles" username="myusername" password="mypassword" method="post" result="httpResponse" timeout="300"&gt; &lt;cfhttpparam type="formfield" name="typeOfReport" value="DailyCSVFile" /&gt; &lt;/cfhttp&gt; </code></pre> <p>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"'</p> <p>When I add this line between my cfhttps:</p> <pre><code>&lt;cfhttpparam type="header" name="Content-Type" value='multipart/related; type="application/xop+xml"' /&gt; </code></pre> <p>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.</p> <p><strong>Update:</strong> 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:</p> <pre><code>&lt;cfsavecontent variable="soapBody"&gt; &lt;cfoutput&gt; &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;s:Body&gt; &lt;queryAvailableReportFiles xmlns="https://brandnameapi.sandbox.serviceprovider.com/contract"&gt; &lt;fileName&gt;DailyCSVFile&lt;/fileName&gt; &lt;/queryAvailableReportFiles&gt; &lt;/s:Body&gt; &lt;/s:Envelope&gt; &lt;/cfoutput&gt; &lt;/cfsavecontent&gt; &lt;cfhttp url="https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles" username="vfapi" password="bPzqQyK3" method="post" result="httpResponse" timeout="300"&gt; &lt;cfhttpparam type="xml" value="#trim(soapBody)#" /&gt; &lt;/cfhttp&gt; </code></pre> <p>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 <a href="https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles" rel="nofollow">https://prismproapi.sandbox.koretelematics.com/4/ReportingAPI.svc/soap/queryAvailableReportFiles</a> 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload