E F R O G

...it all matters to some one.

  • Increase font size
  • Default font size
  • Decrease font size
Home

SOAP, PHP, and ASMX - 'Yes we can!'

E-mail
User Rating: / 0
PoorBest 
Recently, I was tasked with creating a SOAP client to connect to an ASMX resource (Microsoft's take on web services). Now, I am really new to web services (ie, this was my first), but I figured all was in order and that Google would be able to hold my hand through the entire process. In fact, I was so confident in this that I was probably more than a little smug on the phone with the tech guy setting up the web service for us (yes, that's right - I'm important enough that people set up web services specifically for me). It turns out that getting PHP to connect to an ASMX resource isn't as well documented as you would expect. In fact, it seems that web services in general aren't as well documented as one might expect - at least when using PHP (I blame this on the PHP documentation).

Everything I was finding indicated that I needed to install NuSoap (a PHP library) and run the web service client in Non-WSDL mode. For those of you who are just jumping into web services, running in Non-WSDL mode is sort of like pushing a car as a mode of transportation. It is much harder than it needs to be, and you are bound to get some pretty odd looks from people.

Now, here is the simple truth for those running PHP5 (I cannot confirm this on PHP4, and if are running anything earlier than that, it's time to upgrade). Connecting PHP5 to a web service running from an ASMX uri is retardedly simple. Here you go:

$client = new soapclient("https://some/webservice/url.asmx?WSDL");
$result = $client->somefunction(array("param1","someValue"));

'Huzza?' you say? Where did the "?WSDL" come from? Well, every ASMX service (as far as I know) has an accompanying WSDL file, and all of them are accessed the same way. You'll also notice that I didn't need any additional libraries. PHP5's built-in soapclient object is pretty trustworthy, as far as I can tell.

Well, there you have it. Pretty simple? Oh, and if you are stumped as to what my parameters are, here is a quick tutorial. Web services expect the client to send XML. Passing an array to a SOAP method accomplishes this. So, if the service is looking for:

<trackingnumber>123456</trackingnumber>

then you would call your method with:

array("trackingNumber","123456")

PHP's soapclient does all of the magic here. And there you have it. Not so bad, eh? And if anyone tells you that Microsoft-based web services don't offer a WSDL file, laugh and them condescendingly - maybe even throw in a slow clap.
 

Subsc to my personal spam...

This is E F R O G...

Small Investors Versus Big Traders - ShareCrazy.com - Mon 01 Feb, 08:00 AM
The big professional traders rule the markets. If they decide its a selling time, thats what they do and we, as private punters, cant do a thing about it. If most of them buy, rather than sell, theres the opposite and happier- effect.