Header and authentication
| From: | Pierre-Alain Mignot | Date: | Fri, 13 Feb 2009 15:20:09 +0000 |
| Subject: | Header and authentication | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-2897@lists.php.net to get a copy of this message | ||
Hi,
I'm working on a SOAP webservice in WSDL-mode with authentication based on the header of the request.
I have wrote a header method which verify the login/password, but this method is not called when the request is received by the server.
My request looks like this :
<env:Envelope>
<env:Header>
<ns1:AuthHeader>
<login>a login</login>
<password>a hash</password>
</ns1:AuthHeader>
</env:Header>
<env:Body>
<Request>
[...] a request
</Request>
</env:Body>
</env:Envelope>
Here a part of the WSDL :
<xsd:schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:MyUri">
<xsd:element name="AuthHeader">
<xsd:complexType name="AuthHeaderType">
<xsd:sequence>
<xsd:element name="login" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="password" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
[...............]
</xsd:shema>
<message name="AuthHeader">
<part name="AuthHeader" type="tns:AuthHeaderType"/></message> <portType name="MyPortType">
<operation name="myMethod">
<input message="tns:Request"/>
<output message="tns:Response"/>
</operation>
</portType>
<binding name="MyBinding" type="tns:MyPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="myMethod"> <soap:operation soapAction="urn:Action" style="document"/> <input> <soap:header use="literal" message="tns:AuthHeader" part="AuthHeader"/> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation></binding> <service name="MyService">
<port name="MyPort" binding="tns:MyBinding">
<soap:address location="MyLocation"/>
</port>
</service>
And finally here is the PHP code :
[CLIENT]
$client = new SoapClient($wsdl, $options);
# add a header
$header = new SoapHeader('urn:MyUri', 'AuthHeader', new SoapVar(array('login'=>$options['login'], 'password'=>$options['password']), SOAP_ENC_OBJECT));
$client->__setSoapHeaders(array($header));
$Return = $client->MyMethod($request);
[SERVER]
class MyClass {
public function AuthHeader($input) { // try to log }
}
Can someone explain me what I did wrong ?
I tried a lot of different solutions found on the net, but none actually worked.
It looks like the 'ns1' namespace make something wrong ... ??
Thanks in advance,
Regards,
--
Pierre-Alain Mignot
Développeur
CNRS - CLEO
--
Tél.: 04.88.57.69.42
http://cleo.cnrs.fr/
http://www.revues.org/
http://www.lodel.org/
Doc. : http://www.lodel.org/wiki