Wednesday, May 12, 2010

Php Nusoap Sample Client:-Solution for “org.xml.sax.SAXException: Found instance data in body instead of header"

 Consider “< wsdl: message name >” part of wsdl contains 2 parts Let us say one part named SampleRQ” fit in body and other part” Security” belongs to Header.Below is the Sample client that will occupy elements in both body and header part of the Soap Request.

 < ?php
require_once('D:/wamp/www/nusoap-0.7.3/lib/nusoap.php');

$serverpath= http: /localhost: 8080/Sample/services/SampleSOAP';
$namespace="http://services.exg.com/samplereq";
$Username="RPS
$Password="Sample
$Name="Rose”
$Designation="Engineer”;

$body='< SampleRQ xmlns=”http://services.exg.com/samplereq" >
< Name >'."".$Name."".'< /Name >
< Designation >'."".$Designation."".'< /Designation >
< /SampleRQ >';

$header='< ns1:Security xmlns:ns1=http://services.exg.com/secur” >
< ns1:Username >'."".$Username."".'< /ns1:Username >
< ns1:Password >'."".$Password."".'< /ns1:Password >
< /ns1:Security >';

try
{
$SOAPClient = new soapclient($serverpath);
$SOAPClient ->soap_defencoding = "UTF-8";
$SOAPACTION = "http://services.exg.com/Sample/getSample";
$SOAPMESSAGE = $SOAPClient->serializeEnvelope($body, $header,array(),'document', 'literal');
$RESULT = $SOAPClient->send($SOAPMESSAGE, $SOAPACTION);
print_r($RESULT);
}
catch(Exception $e)
{
print $e;
}

// Display the request and response
echo '< h2 >Request< /h2 >';
echo '< pre >' . htmlspecialchars($SOAPClient->request, ENT_QUOTES) . '< /pre >';
echo '< h2 >Response< /h2 >';
echo '< pre >' . htmlspecialchars($SOAPClient->response, ENT_QUOTES) . '< /pre >';
unset($SOAPClient);


?>

No comments:

Post a Comment