This article has been dead for over three months
You
Hi All,
I need to create a new web-service by using php. And I need to use SOAP RPC/encoded for implementing this. I also need to authenticate the soap request using soap header information. Before doing main task that I have created a WSDL file, client and server files using php.
I have managed to send the soap request with header. But I am unaware of using the header information in the server side. That is I don't know how to check the header value is correct or not.
And I got error while I have setting "must-understand" to 1 or true. The error is "Header not understood".
I am listing our WSDL, soap request, client and server here.
Please guide me to create a good web service with authentication using soap headers.
Thank in advance
By Dipu
WSDL
<?xml version="1.0" encoding="ISO-8859-1"?>
adds two string values and returns the result
SOAP Request
dipucatalog1catalogTest111
Client File
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("catalog.wsdl",array('trace' => 1 ));
$catalogId='catalog1';
$functions=$client->__getFunctions();
echo '<pre>';
print_r($functions);
// $soapHeader=new SoapHeader('http://soapinterop.org/echoheader/','username','hello world');
// $response = $client->getCatalogEntry('catalog1','catalogTest111', $soapHeader);
/*$bodyArr = array('catalog1', 'catalogTest111');
$response = $client->__soapCall('getCatalogEntry', $bodyArr,NULL,$soapHeader,NULL); */
// echo '--'.$client->__getLastRequest().'--';
$ns = 'http://namespace.example.com/';
//Body of the Soap Header.
$header = new SOAPHeader($ns, 'username', 'dipu');
$testArr = array('catalogId'=>'catalog1','catalogId2'=>'catalogTest111');
$response=$client->__soapCall("getCatalogEntry",$testArr,NULL, $header);
//Create Soap Header.
echo $client->__getLastRequest();
//echo $client->__getLastRequestHeaders();
echo $response;
?>
Server File
<?php
function getCatalogEntry($catalogId,$catalogId2) {
if($catalogId=='catalog1')
return "<HTML>
<HEAD>
<TITLE>Catalog</TITLE>
</HEAD
<BODY>
<p> </p>
<table border>
<tr><th>CatalogId</th>
<th>Journal</th><th>Section
</th><th>Edition</th><th>
Title</th><th>Author</th>
</tr><tr><td>catalog1</td>
<td>IBM developerWorks</td><td>
XML</td><td>October 2005</td>
<td>JAXP validation</td>
<td>Brett McLaughlin</td></tr>
<tr><td>$catalogId2</td>
<td>IBM developerWorks</td><td>
XML</td><td>October 2005</td>
<td>JAXP validation</td>
<td>Brett McLaughlin</td></tr>
</table>
</BODY>
</HTML>";
elseif ($catalogId='catalog2')
return "<HTML>
<HEAD>
<TITLE>Catalog</TITLE>
</HEAD
<BODY>
<p> </p>
<table border>
<tr><th>CatalogId</th><th>
Journal</th><th>Section</th>
<th>Edition</th><th>Title
</th><th>Author
</th></tr><tr><td>catalog1
</td><td>IBM developerWorks</td>
<td>XML</td><td>July 2006</td>
<td>The Java XPath API
</td><td>Elliotte Harold</td>
</tr><tr><td>$catalogId2
</td><td>IBM developerWorks</td>
<td>XML</td><td>July 2006</td>
<td>The Java XPath API
</td><td>Elliotte Harold</td>
</tr>
</table>
</BODY>
</HTML>";
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("catalog.wsdl");
$server->addFunction("getCatalogEntry");
$server->handle();
?>