Précédent   Forum des professionnels en informatique > PHP > Langage > Syntaxe
Syntaxe Forum d'entraide sur la syntaxe de PHP et la POO. Avant de poster -> FAQ syntaxe, Cours d'initiation et cours de POO
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 01/02/2012, 15h50   #1
Invité de passage
 
Inscription : octobre 2010
Messages : 18
Détails du profil
Informations forums :
Inscription : octobre 2010
Messages : 18
Points : 3
Points : 3
Par défaut Communication Php avec Web service

Bonjour,

J'espère étre dans la bonne rubrique pour vous exposer mon problème.

Voilà je cherche à travers un script en php à communiquer avec un web service.
Les spécificité sont : j'utilise une authentification NTLM au lieu d'une authentification basique.

Voici mon script :
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
 
class NTLMSoapClient extends SoapClient {
	function __doRequest($request, $location, $action, $version) {
		$headers = array(
			'Method: POST',
			'Connection: Keep-Alive',
			'User-Agent: PHP-SOAP-CURL',
			'Content-Type: text/xml; charset=utf-8',
			'SOAPAction: "'.$action.'"',
		);
		$this->__last_request_headers = $headers;
		$ch = curl_init($location);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_POST, true );
		curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
		curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
		curl_setopt($ch, CURLOPT_USERPWD, $this->UserName.':'.$this->Password);
		$response = curl_exec($ch);
		return $response;
	}
	function __getLastRequestHeaders() {
		return implode("\n", $this->__last_request_headers)."\n";
	}
}
 
class ExchangeNTLMSoapClient extends NTLMSoapClient 
	{ 
		protected $UserName = 'mon.login@mail'; 
		protected $Password = 'monpassword'; 
	}
 
class NTLMStream {
	private $path;
	private $mode;
	private $options;
	private $opened_path;
	private $buffer;
	private $pos;
 
	public function stream_open($path, $mode, $options, $opened_path) {
		$this->path = $path;
		$this->mode = $mode;
		$this->options = $options;
		$this->opened_path = $opened_path;
		$this->createBuffer($path);
		return true;
	}
 
	public function stream_close() {
		curl_close($this->ch);
	}
 
	public function stream_read($count) {
		if(strlen($this->buffer) == 0) {
			return false;
		}
		$read = substr($this->buffer,$this->pos, $count);
		$this->pos += $count;
		return $read;
	}
 
	public function stream_write($data) {
		if(strlen($this->buffer) == 0) {
			return false;
		}
		return true;
	}
 
	public function stream_eof() {
		if($this->pos > strlen($this->buffer)) {
			return true;
		}
		return false;
	}
 
	public function stream_tell() {
		return $this->pos;
	}
 
	public function stream_flush() {
		$this->buffer = null;
		$this->pos = null;
	}
 
	public function stream_stat() {
		$this->createBuffer($this->path);
		$stat = array(
			'size' => strlen($this->buffer),
		);
		return $stat;
	}
 
	public function url_stat($path, $flags) {
		$this->createBuffer($path);
		$stat = array(
			'size' => strlen($this->buffer),
		);
 
		return $stat;
	}
 
	private function createBuffer($path) {
		if($this->buffer) {
			return;
		}
		$this->ch = curl_init($path);
		curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
		curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
		curl_setopt($this->ch, CURLOPT_USERPWD, $this->UserName.':'.$this->Password);
		$this->buffer = curl_exec($this->ch);
		$this->pos = 0;
	}
}
 
class ExchangeNTLMStream extends NTLMStream 
	{ 
		protected $UserName = 'mon.login@mail'; 
		protected $Password = 'monpassword'; 
	}
 
stream_wrapper_unregister('http');
stream_wrapper_register('http', 'ExchangeNTLMStream') or die("Failed to register protocol"); 
$client = new ExchangeNTLMSoapClient("http://www.monwebservice/wseditic/wscheck.asmx?WSDL",
								array( 'soap_version'	=> SOAP_1_2));
$params = array (
	'Login' =>'{mon.login@mail}');
$rawXMLresponse = $client->GetApprenant($params)->GetApprenantResult->any;
stream_wrapper_restore('http');
?>
Je fais appel ici à une fonction banale "GetApprenant" pour testé que mon script marche. Il devrait donc me retourné toutes les informations concernant l'apprenant mis en paramètre, hors lors de l'execution de celui-ci, il me retourne l'erreur suivante:

Code :
"Fatal error: Uncaught SoapFault exception: [soap:Client] Le serveur n'a pas reconnu la valeur de l'en-tête HTTP SOAPAction : "http://si.rouenbs.fr/GetApprenant". in C:\wamp\www\LienWebServiceNTLM1.php:171 Stack trace: #0 C:\wamp\www\LienWebServiceNTLM1.php(171): SoapClient->__call('GetApprenant', Array) #1 C:\wamp\www\LienWebServiceNTLM1.php(171): ExchangeNTLMSoapClient->GetApprenant(Array) #2 {main} thrown in C:\wamp\www\LienWebServiceNTLM1.php on line 171"
Une Idée sur la cause ?

Merci d'avance,
bobo27110 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/02/2012, 16h04   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 239
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 239
Points : 8 624
Points : 8 624
l'erreur est assez explicite non ? enlève ton entête
__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 10
Vieux 01/02/2012, 16h13   #3
Invité de passage
 
Inscription : octobre 2010
Messages : 18
Détails du profil
Informations forums :
Inscription : octobre 2010
Messages : 18
Points : 3
Points : 3
Oki merci je test.
bobo27110 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/02/2012, 16h52   #4
Invité de passage
 
Inscription : octobre 2010
Messages : 18
Détails du profil
Informations forums :
Inscription : octobre 2010
Messages : 18
Points : 3
Points : 3
Bon j'arrive maintenant à une autre erreur :p, sa progresse :

Ma nouvelle erreur se situe à cette ligne :

Code :
$rawXMLresponse = $client->GetApprenant($params)->GetApprenantResult
L'erreur est la suivante :

Code :
Catchable fatal error: Object of class stdClass could not be converted to string in C:\wamp\www\LienWebServiceNTLM1.php
Il n'y pas une fonction convertToString en PHP ?
bobo27110 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/02/2012, 17h18   #5
Modérateur
 
Inscription : septembre 2010
Messages : 7 239
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 239
Points : 8 624
Points : 8 624
...

fais un var_dump dessus et tu comprendras
__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 10
Vieux 02/02/2012, 09h28   #6
Invité de passage
 
Inscription : octobre 2010
Messages : 18
Détails du profil
Informations forums :
Inscription : octobre 2010
Messages : 18
Points : 3
Points : 3
J'ai effectué un var_dump, j'obtiens maintenant un message clair et sans erreur:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
object(stdClass)[3]
  public 'ProgrammeFC' => string '|MBA|OM|EXECMBA|ManRayon|PGEFC|' (length=31)
  public 'Utilisateur' => 
    object(stdClass)[4]
      public 'Langue' => string 'fr' (length=2)
      public 'Utilisateur' => string 'ESC-ROUEN\mon.login' (length=19)
  public 'Id' => int 0
  public 'Login' => string '' (length=0)
  public 'Code' => string '' (length=0)
  public 'Nom' => string '' (length=0)
  public 'Prenoms' => string '' (length=0)
  public 'Programme' => string '' (length=0)
  public 'NomPrenom' => string '' (length=0)
  public 'EtatInscription' => string '' (length=0)
  public 'Actif' => boolean false
  public 'EnEnseignement' => boolean false
  public 'Diplomant' => boolean false
  public 'Regime' => string '' (length=0)
  public 'Annee' => string '0' (length=1)
  public 'Mail' => string '' (length=0)
  public 'Mobile' => string '' (length=0)
  public 'NumeroCarte' => string '' (length=0)
  public 'DateFin' => string '0001-01-01T00:00:00' (length=19)
Mais je n'ai toujours aucunes informations retourné dans les champs, pourquoi ?
bobo27110 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/02/2012, 09h53   #7
Modérateur
 
Inscription : septembre 2010
Messages : 7 239
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 239
Points : 8 624
Points : 8 624
parce que c'est un object donc si tu veux afficher quelque chose, faut avoir accès au propriété

par exemple

__________________
http://blog.stealth35.com/
stealth35 est actuellement connecté   Envoyer un message privé Réponse avec citation 10
Vieux 02/02/2012, 10h36   #8
Invité de passage
 
Inscription : octobre 2010
Messages : 18
Détails du profil
Informations forums :
Inscription : octobre 2010
Messages : 18
Points : 3
Points : 3
Ouki merci beaucoup pour toutes ces informations
bobo27110 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h32.


 
 
 
 
Partenaires

Hébergement Web