[Web Service] WSDL soapHeader PHP authentification
Bonjour
je souhaite développer un web service en SOAP.
Je dois passer des paramètres de login et de mdp dans le header, ce que je fais, mais le pb est que je n'arrive pas à les récuperer du cote serveur (de fais ma WS me renvoie toujours false quelque soit la valeur passé).
Alors le pb pourrais se trouver du cote du fichier WSDL.
Ce que je souhaitais savoir, c'est si la méthode qui permet l'authentification cote serveur dois se trouver dans le fichier WSDL, et dans ce cas, si celle méthode dois avoir un "code spéciale " dans le wsdl.
Voici mon code qui toutefois reste dans ce qu'on trouve sur le web.
Cote Client :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
class UserPasswordPair
{
public $Username;
public $Password;
function __construct($Username, $Password)
{
$this->Username = $Username;
$this->Password = $Password;
}
}
$credentials = new UserPasswordPair("test", "test");
$soapAuthenticator = new SoapVar(
$credentials,
SOAP_ENC_OBJECT,
"headerAuthentify");
$authHeader = new SoapHeader("http://127.0.0.1/clientTest/","headerAuthentify",$soapAuthenticator,false);
try
{
$client = new SoapClient( 'http://127.0.0.1/clientTest/fiche.wsdl', array ('trace'=>true));
$InfoResponse = $client->__soapCall("getServerInfo",array(),NULL,$authHeader); |
Cote Serveur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
class mySoapClass {
public $passed;
public $use;
public $pass;
public function headerAuthentify( $parameters){
$this->use = $parameters;
$this->pass = $NewPart;
if($parameters =="test"){
$this->passed = true;
} else {
$this->mySoapErr( );
}
}
public function mySoapErr(){
print "Erreur";
}
public function getServerInfo(){
$this->headerAuthentify( $username, $password );
if(!$this->passed){
return array('info' => 'Inconnu : '.$this->use);
}
return array('info' => 'ok');
}
}
$server = new SoapServer('http://127.0.0.1/clientTest/fiche.wsdl', array('trace' => 1, 'soap_version' => SOAP_1_2));
$server -> setclass('mySoapClass');
$server->handle(); |
Cote wsdl :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
<?xml version="1.0"?>
<definitions name="CSP"
targetNamespace="urn:CSP"
xmlns:tns="urn:CSP"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:typens="urn:CSP"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:CSP">
<xsd:complexType name="MyInfo">
<xsd:all>
<xsd:element name="info" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="getServerInfo">
<part name="none" type="xsd:int"/>
</message>
<message name="getServerInfoResponse">
<part name="value" type="typens:MyInfo"/>
</message>
<portType name="CspPorts">
<operation name="getServerInfo">
<input message="getServerInfo"/>
<output message="getServerInfoResponse"/>
</operation>
</portType>
<binding name="MyBinding" type="typens:CspPorts">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getServerInfo">
<soap:operation
soapAction="http://127.0.0.1/clientTest/fiche.wsdl"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MyWebService">
<documentation>Mon Service web</documentation>
<port name="CspPorts" binding="typens:MyBinding">
<soap:address location="http://127.0.0.1/clientTest/test.php"/>
</port>
</service>
</definitions> |
Merci