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.
WSDL
<?xml version="1.0" encoding="ISO-8859-1"?>
adds two string values and returns the result
Hum, I don’t think you’ll got lot of support here as it’s more wM centric.
May I suggest to send your request directly to a PHP forum ?
Anyway, I can’t help you as I have wrote only PHP client up to now But if you find an answer, can you please copy it here as I’m interested on the subject.
Thank you for your reply. I have manged to solve the problem by modify the WSDL , server file and the client file. Now It is able to send and manipulate the soap header information.
<?php
class SayHello {
public function getHello($inmessage) {
return "Hello $inmessage!";
}
public function validate($username,$password) {
if($username!='username' || $password!='password'){
throw new SOAPFault("Incorrect username and password combination.", 401);
}
}
} //end class
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("test_class.wsdl");
$server->setClass("SayHello");
$server->handle();
$functions=$server->getFunctions();
?>
Client File
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("test_class.wsdl",array('trace' => 1 ));
$catalogId='catalog1';
$functions=$client->__getFunctions();
echo '<pre>';
print_r($functions);
class SOAPAuth {
public $username;
public $password;
public function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
}
}
$ns = 'http://namespace.example.com/';
//Body of the Soap Header.
if(@$_GET['username']!='')$username =$_GET['username'];else $username = 'username';
if(@$_GET['password']!='')$password =$_GET['password'];else $password = 'password';
$auth = new SOAPAuth($username,$password);
$header = new SOAPHeader('urn:example.org/auth', 'validate', $auth);
$testArr = array('testString'=>'catalog1');
try{
$response=$client->__soapCall("getHello",$testArr,NULL, $header);
echo $client->__getLastRequest();
print_r($response);
}catch (SOAPFault $exception) {
echo '<pre>';
print_r($exception);
}
?>