Correct namespace format for soap 1.2 payload

william.skellorn.bto.org's picture
I have set-up wso2 PHP WS 2.1.0 framework on a centos server (PHP 5.2.10, apache/2.2.3) with the native PHP SOAP extension active. The sample WS clients work fine. The only difference in my WS installation to the default is that the wsf files are in the path structure /usr/lib64/php/modules/wsf_c/ instead of /var/lib/. I am having trouble generating a complete SOAP request using the following client script - <?php ini_set('display_errors',1); error_reporting(E_ALL); $reqPayloadString = <<<XML <soap:Envelope xmlns:soap=”http://www.w3.org/2003/05/soap-envelope” xmlns:typ=”http://service.dataxmldistribution.argos.cls.fr/types”> <soap:Header/> <soap:Body> <typ:xmlRequest> <typ:username>user</typ:username> <typ:password>password</typ:password> <typ:platformId>'1,2,3,4,5'</typ:platformId> <typ:nbDaysFromNow>10</typ:nbDaysFromNow> </typ:xmlRequest> </soap:Body> </soap:Envelope> XML; $reqMessage = new WSMessage($reqPayloadString); try { $client = new WSClient(array(                 "wsdl" => "http://ws-argos.cls.fr/argosDws/services/DixService?wsdl",                 "to" => "http://ws-argos.cls.fr/argosDws/services/DixService",                 "useSOAP" => 1.2,                 "action"=>"getXml"                 ));                $resMessage = $client->request($reqPayloadString);                printf("Response = %s <br/>\n", htmlspecialchars($resMessage->str)); } catch (Exception $e) {     if ($e instanceof WSFault) {         printf("Soap Fault: %s\n", $e->code);     } else {         printf("Message = %s\n",$e->getMessage());     } } printf("<br/> Request = %s </br>",             htmlspecialchars($client->getLastRequest())); printf("<br/> Response = %s </br>",             htmlspecialchars($client->getLastResponse())); ?> The script returns the following - Message = Invalid Input Message Request = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope> Response = <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:lang="en">Fault occurred while processing.</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope> I've also attached the client log, which shows one error - 'om_document.c(102) Unable to get root node'. I assume that the fact that the xml request is missing from within the body element in the print-out from getLastRequest that I need to format the package xml differently - possibly with namespaces? I am usure how this should look, so would be extremely gratefully of any advice, if this is the issue. I have tried this request with and without the 'wsdl' referenced in the WSClient array, and tried defining the payload as an array instead of an XML string (as you might with a native SOAP request). Thank you, William
AttachmentSize
wsf_php_client.log_.txt13.13 KB
mbremer.rssd.esa.int's picture

Hi William, Your payload

Hi William, Your payload string should not contain the whole XML message, but only the section of the message body. The header is dealt with via the WSHeader object that you add via the WSMessage method (inputHeaders section of the parameter array). The envelope is automatically wrapped around the message. This means you can't define your namespaces in the envelope, but you have to define it in the body. Have a look at the following discussion, where somebody also had the problem of defining the namespaces: http://wso2.org/forum/thread/20321 Regards, Martin
william.skellorn.bto.org's picture

Martin - Thanks for the

Martin - Thanks for the speedy reply and clarification. I'll try and construct something a bit more compliant and report back. William.
william.skellorn.bto.org's picture

Martin,1. From reading the

Martin, 1. From reading the thread you referenced I made a literal attempt at defining the namespace by adding it to the xmlrequest tag as seen in image attached (after removing the envelope and body containers). This gave the same response as before. Could you describe how you would add namespace declarations to the XML content in the image? 2. From your reply I'm assuming that because the header didn't have any declarations in it, I don't need to invoke it using inputHeaders? Or is it always required for a request going to a SOAP service? Apologies, I'm clearly out of my depth here!
mbremer.rssd.esa.int's picture

Hi William, Your payload

Hi William, Your payload string looks OK now. Since you are not modifying the XML header, you don't need to set the input headers, that is also true. Creating a WSMessage object (just above the try) looks unnecessary. I think the problem is in the WSClient definition. I don't use the "wsdl" parameter, I point the "to" field to the WSDL location, like this: $client = new WSClient(array("to" => $wsdl, "useSOAP" => 1.2)); I could be wrong, but I think the "wsdl" and "action" parameters are used for WSService and not for WSClient. Cheers, Martin
william.skellorn.bto.org's picture

Alternate option - WSDL and proxy

Thanks for your response Martin. I attempted what you suggested but got the error 'soap_builder.c(845) SOAP message does not have a SOAP envelope element'. I am now trying the alternative method of first calling the WSDL as reference to identify my array of values and then call a proxy. From the error log I can see that the WSDL is found and the action understood, but it fails with a segmentation fault after invoking context_handler in PostDispatch (immediately before the Response Buffer should be returned). The wso2 examples for WSDL mode Client using WSDL 1.1 and WSDL mode Client using WSDL 2.0 both work using the same server. I've attached images of the script and error log. William