HOWTO: Debug web services problems

sugarcrmdevelopers —  April 9, 2012 — Leave a comment

I came across this post the other day, and just like every other time I encounter a post like this, I immediately push back to the poster to try and debug the calls. And then a light bulb kicked off in my head. “John, why don’t you give people a guide on how to debug these issues?”. So here’s that post.

There tends to be two sorts of issues I see that people report back on web services calls…

  1. The call isn’t returning the data I’m expecting and/or doing what I expected it to do.
  2. The call seems to be failing silently ( i.e. returning no data back, or not being able to parse the response )

The first issue tends to revolve around the oh-so-tempermental set_relationships() call, which I wrote a whole blog post on a while back, so I’ll let you dig in there if you are seeing issues with that call.

Most of the other issues around the calls not working as expected revolve around some weirdness with using SOAP calls, as the SOAP used in Sugar currently is the more XML-RPC style SOAP 1.1 one versus the more current SOAP 1.2. Most of the time configuring your client to use SOAP 1.1 will fix this, but in general we recommend using the REST interface if at all possible. This is because of the ease of constructing the REST calls, since the less strictness can make it easier to build the right data structures for dealing with the calls. Also as a bonus, not having the overhead of SOAP envelope construction and handling makes the interaction a whole bunch faster as well. If you must use SOAP, be sure to cache the WSDL or go in WSDL-less mode when you move to production to also save some overhead.

Now the bigger issue I see is when calls silently fail. The only thing is that they usually do report back some sort of error, you just need to know where to look. In most cases, this is in the raw request returned back. To find this depends upon the library and language you are using; for example, with NuSOAP try this snippet.


$soapClient = new nusoapclient($soapURL,false);

$result = $soapClient->call(
// parameters

if ( !$result ) {
var_dump('SOAP Error ('.$soapClient->faultcode.'): '
. $soapClient->faultstring.': '.$soapClient->faultdetail
. ' HTTP Response: '.$soapClient->response

The key is to check the SOAP fault codes and the raw HTTP response, as many times there will be extraneous messages outside the expected payload that makes parsing the envelope impossible. Finding them and resolving them will help out the problems being seen. The same issues also plague REST calls as well, since most scripts assume the payload being returned is JSON or serialized data, and anything not that will mess up parsing the response correctly.

What other issues do you see when working with our web services? I’d love to hear about them in the comments or on Twitter.

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s