Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /share/CACHEDEV1_DATA/Web/www/libraries/UBBcode/text_parser.class.php on line 228

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /share/CACHEDEV1_DATA/Web/www/libraries/UBBcode/text_parser.class.php on line 228

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /share/CACHEDEV1_DATA/Web/www/libraries/UBBcode/text_parser.class.php on line 228
Using PHP's SoapClient class with .NET servers

Comments Blog About Development Research Sites

Using PHP's SoapClient class with .NET servers

May 6, 2008
One of the many great new features in the later PHP releases is it's SoapClient class. In theory it provides an easy to use way to interact with soap servers and clients.

Naturally, there is a small hitch: it's default layout when working with WSDL files is such that .NET servers don't seem to understand it. The first time I encountered this I did the sleazy thing, ie, build my own soap client interface that send raw requests over an opened CURL connection. Worked magnificantly, with the only drawback that the entire library (granted, including comments) was almost 400 lines of code spread out over 4 classes. Not something you'd write during your coffee break then.

Now in theory the PHP's SoapClient class should be able to do all that and more and be a lot faster at it too (since it's a compiled library instead of interpretable PHP code), so when I had to connect to yet another .NET server I decided to give it one more shot. I knew how the requests should be send (since I had written an interface that build raw requests itself) and, with the __getLastRequest() member I could also see how they were send instead.

Armed with this knowledge, the comments on PHP.net and the documentation for the .NET server I soon figured out what to do. Instead of assigning parameters to the client object like you'd expect you should instead assign them to a stdClass object like this:
Code (php) (nieuw venster):
1
$parameters -> objRequest -> $variable = $value;


The second trick is that instead of calling the function directly we need to call it manually using the __call member. Don't ask me why, but that's the only way it seems to produce correct SOAP requests:
Code (php) (nieuw venster):
1
$client -> __call($function, array($function => $parameters));


Now all this is quite tiresome to do so I wrote my own interface to encompass the PHP one. What it does is basicly fix the (broken) functionality you would expect from a soapClient class, to such an extend that you can now do this:
Code (php) (nieuw venster):
1
2
3
4
$interface =  new SoapClientInterface('http://location.to/wsdl.file');
$interface -> foo = 'bar';
$interface -> bar = 'some other value';
$result    =  $interface -> getBar();


The class is quite small but should save you some typing. You can find it here for download

FragFrog out!

New comment

Your name:
Comment: