Bonjour
J essaye vainement de m'authentifier en envoyant un header a un service Soap , la classe serveur n entre jamais dans la methode header
Quel qu un peut il m aider .
Voici mon script client
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
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://schemas.xmlsoap.org/ws/2002/07/utility","headerAuthentify",$soapAuthenticator,false);
 
try 
{	
$client = new SoapClient( 'fiche.wsdl', array ('trace'=>true));
$InfoResponse = $client->__soapCall(
"getServerInfo",array(),NULL,$authHeader);										 
   $call = $client->__call('getServerInfo',array());	
  echo $call->info;
}
 
catch (SoapFault $exception)
{
	print($exception);
}
serveur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
class mySoapClass {
    public $passed;
 
    public function headerAuthentify( $username, $password ){
 
        if($username =="test"){
            $this->passed = true;
        } else {
            $this->mySoapErr( );
        }
    }
 
	public function mySoapErr(  ){
      print "Erreur";
    }
    public function getServerInfo(){
 
        if(!$this->passed){
             return array('info' => 'Inconnu'.$this->login);
        }
		 return array('info' => 'ok');
    }
 
}
 
try {
    $server = new SoapServer('fiche.wsdl',  array('trace' => 1, 'soap_version' => SOAP_1_1));
    // On définit la classe qui va gérer les requètes SOAP
    $server -> setclass('mySoapClass');
} catch (Exception $e) {
    echo $e;
}
et enfin ma fiche wsdl
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?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:8080/security/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:8080/security/server.php"/>
    </port>
  </service>
 
</definitions>