Debugging webservices with Charles

Debugging webservices can be tedious. You can save yourself quite a lot of time by using a network debugging proxy tool such as Charles.
Get it here and install it.
Open Charles and enable proxy. Set the proxy port to something like 8888

Charles proxy settings. Port 8888

Add proxyport and proxyserver attributes to your CFHTTP tag (I assume that you develop locally).

   <cfhttp url="api.nastysoapservice.com" proxyport="8888" proxyserver="127.0.0.1" name="returnXML" />

You are set. All webservice traffic is now going through Charles.
Let’s try to call a KirupaFX SOAP webservice, returning a list of top 10 movies of all times :) You can find the WSDL at http://www.kirupafx.com/WebService/TopMovies.asmx?WSDL

<!--- Define XML for SOAP call --->
<cfset requestXML = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><ns1:GetTop10 xmlns:ns1='http://www.kirupafx.com' /></soap:Body></soap:Envelope>" />
<!--- Set webservice URL --->
<cfset urlStr = "http://www.kirupafx.com/WebService/TopMovies.asmx" />
<!--- Call the webservice. Note the proxyport and proxyserver attributes --->
<cfhttp url="#urlStr#" method="post" result="responseXML" compression="false" timeout="2" proxyport="8888" proxyserver="localhost">
	<cfhttpparam type="header" name="content-type" value="text/xml">
	<cfhttpparam type="header" name="content-length" value="#len(trim(requestXML))#">
	<cfhttpparam type="header" name="accept-encoding" value="no-compression" />
	<cfhttpparam type="header" name="charset" value="utf-8">
	<cfhttpparam type="header" name="Port" value="/GetTop10" />
	<cfhttpparam type="xml" value="#trim(requestXML)#" />
</cfhttp>
<!--- Process the results --->
<cfset moviesXML = XMLParse(responseXML.filecontent) /> 
<cfset moviesArr = moviesXML['soap:Envelope']['soap:Body']['GetTop10Response']['GetTop10Result'].XMLChildren /> 
<!--- Dump the array containing movie titles --->
<cfdump var="#moviesArr#" />

Load the page in your browser. Let’s check Charles:
Click the webservice call in the left pane to show the details:

Click ‘Contents->SOAP’ to review the details of all request/response elements

Click ‘Contents->XMLText’ to view raw XML

Click ‘Contents->XML’ to browser through XML nodes

Click ‘Contents->Headers’ to inspect http headers

Tips

  • Click Proxy->Recording settings->Include and add a hostname to limit your proxy recording session to one or more hosts
  • Click Proxy->Recording settings->Include and uncheck all hosts to view all server sessions