Copy link to clipboard
Copied
I'm trying to find out what Coldfusion actually does when you instantiate or invoke a web service as a coldfusion object, either with the cfobject or cfinvoke tags. Let's say I have the following code:
<cfinvoke webservice="https://#application.webServiceURL#/getArticle.cfc?wsdl" method="getArticle" returnvariable="myArticle" timeout="10">
<cfinvokeargument name="Article" value="3">
</cfinvoke>
What's actually happening behind the scenes here? Is Coldfusion making an HTTPS request? Is it a GET or a POST request? Or is something else I don't know about? What is the functional difference between that syntax versus something like this:
<cfhttp url="https://#application.webServiceURL#/getArticle.cfc?method=getArticle&Article=3" method="get" result="resultJSON" timeout="10">
<cfhttpparam type="header" name="Accept" value="application/json" />
</cfhttp>
<cfset myArticle= DeSerializeJSON(resultJSON.FileContent) />
Any help you have would be much appreciated. I'm just trying to wrap my head around what's going on under the hood here.
Copy link to clipboard
Copied
The short answer is that, yes, CF is using CFHTTP to fetch data from the web service. The details will depend on the type of web service being invoked. In your example, the web service URL ends with this:
"getArticle.cfc?wsdl"
This typically indicates that the web service has a WSDL description, which usually means a SOAP service. SOAP services are kind of complicated. The SOAP client (CF) fetches the WSDL description, which tells the client the URLs for whatever services it includes. The SOAP service then makes a second HTTP call to the exact service, and sends and receives whatever data it's supposed to send and receive at that point.
Now, SOAP is kind of complicated - which is probably why people don't use it so much any more. A SOAP service describes the data types that the SOAP client should be using, and the SOAP client has to build proxies for those data types. CF includes a third-party library called Apache Axis for this. You don't work with Apache Axis directly unless things have really gone wrong.
Nowadays, instead of using SOAP, most web services use REST, which is just a matter of swapping out generic XML (instead of SOAP) or JSON to represent objects. REST is a lot looser about all the interpretation and need to proxy data types - that all becomes your job instead. Fortunately, it's not an especially difficult job. It also moves some of the "intent" from the SOAP/WSDL stuff to the HTTP verb used when you make the service call.
https://en.wikipedia.org/wiki/Representational_state_transfer
I've probably oversimplified things just a bit here, but you should get the drift.
Dave Watts, Eidolon LLC
Copy link to clipboard
Copied
> Is Coldfusion making an HTTPS request?
In both cases, yes. The request to the webservice is HTTPS.
However, if your site is HTTP, then the request to the CFM page running the tags cfinvoke and cfhttp will be HTTP.
> Is it a GET or a POST request?
The cfinvoke does a POST (with arguments being passed in the request body), whereas the cfhttp does a GET (with arguments being passed in the query-string).