Page 1 of 1

Converting ASP Soap to PHP

Posted: Sat Oct 20, 2007 2:39 pm
by Cerddaf
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm converting an ASP system with PHP, and I need to replace a SOAP call.
I've checked out the various Soap tutorials and fora, and the code seems to be be not the normal SOAP usage.
It does not use WSDL, just xml messages.

Anyone able to help with the parameters to be used in the PHP version.


------------------------
ASP code to be converted

[syntax="asp"]set objHTTP = CreateObject("Msxml2.ServerXMLHTTP")
'Set up to post to our localhost server

' PRODUCTION SERVER
objHTTP.open "post", "http://123.456.654.321/thehost/interface/xml",false

'Set a standard SOAP/ XML header for the content-type
objHTTP.setRequestHeader "Content-Type", "text/xml"
'Make the SOAP call
objHTTP.send strEnvelope
strOut = objHTTP.responsetext
strOut = replaceUNICODE(strOut)
GetSoap = strOut

------------------------

I assume the PHP should look something like this!

Code: Select all

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/",
                                     'style'    => SOAP_DOCUMENT,
                                     'use'      => SOAP_LITERAL
                                     )); 
??Do I need a parameter for encoding as well ??


$Response = $client->__doRequest ( string request, string location, string action, int version )
... and what should values should I use for <request> <location> <action> <version >


Everah | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Oct 20, 2007 6:38 pm
by neophyte
Can you tell us more about the functions you need to invoke on the soap server?

Looks like it is running UTF8 so you can specifiy it in your options array.

SOAP is a very difficult thing to work with.
SoapClient->__getLastRequest() - Returns last SOAP request
SoapClient->__getLastRequestHeaders() - Returns last SOAP request headers
SoapClient->__getLastResponse() - Returns last SOAP response
SoapClient->__getLastResponseHeaders() - Returns last SOAP response headers
Don't forget to use these when debugging along with try/catch SOAPFault.

Posted: Sun Oct 21, 2007 9:03 am
by Cerddaf
Everah, Thanks for the correction.

Neophyte
It's just sending an XML message and then reading an XML message back.

Posted: Sun Oct 21, 2007 6:57 pm
by Weirdan
Straightforward port would be:

Code: Select all

<?php
function soapRequest($envelope) {
	/*
	set objHTTP = CreateObject("Msxml2.ServerXMLHTTP")
	*/
	$http = curl_init();

	/*
	'Set up to post to our localhost server

	' PRODUCTION SERVER
	objHTTP.open "post", "http://123.456.654.321/thehost/interface/xml",false
	this is invalid ip address btw
	*/
	curl_setopt($http, CURLOPT_URL, 'http://123.456.654.321/thehost/interface/xml');
	curl_setopt($http, CURLOPT_POST, true);

	/*
	'Set a standard SOAP/ XML header for the content-type
	objHTTP.setRequestHeader "Content-Type", "text/xml"
	*/
	curl_setopt($http, CURLOPT_HTTPHEADER, 'Content-type', 'text/xml');

	/*
	'Make the SOAP call
	objHTTP.send strEnvelope
	*/
	curl_setopt($http, CURLOPT_POSTFIELDS, $envelope);
	curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
	$out = curl_exec($http);

	/*
	strOut = objHTTP.responsetext
	strOut = replaceUNICODE(strOut)
	GetSoap = strOut 
	*/
	return replaceUnicode($out);
}
?>

Posted: Mon Oct 22, 2007 5:08 pm
by Cerddaf
Thank you, worked fine.

So the references to Soap where a complete red herring!

But at least I've found a new and useful piece of PHP

Posted: Tue Oct 23, 2007 5:41 pm
by Weirdan
So the references to Soap where a complete red herring!
No, soap is available in PHP, but:
1. You did it this way in ASP and it worked for you while php soap extension did not - so why bother with it?
2. I used soap in the past and it seems to me that with soap you need to stick to what works for you. Honestly, I dislike it, at least its implementation in PHP's soap extension.