Bonjour à vous,
Je post ici car je suis en train de porter un web service PHP sous C# (Visual Studio 2010).
Le projet est en Framework 4 mais le web service a été rajouté comme référence compatible Framework2 (en fonction du wsdl).
Je travail pour le moment juste sur un web service classique type "HelloWorld".
Ce web service fonctionne correctement en PHP et en C#.
Dès que je l'authentification est activé sur l'Apache par le .htaccess (Côté Serveur du Web Service) alors là lorsque je lance mon client C# j'obtiens cette erreur :
Dans les logs d'Apache je vois cette ligne :Exception : WebException
La demande a échoué avec l'état HTTP 400 : Bad Request.
Le code côté client C# est le suivant :[Thu Feb 02 23:52:06 2012] [error] [client XX.XX.XX.XX] Invalid URI in request <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="https://www.domaine.com/api/helloworld/webservices.php?wsdl" xmlns:types="https://www.domaine.com/api/helloworld/webservices.php?wsdl/encodedTypes" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xmlns
sd="http://www.w3.org/2001/XMLSchema"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><tns:bonjour><prenom xsi:type="xsd:string">Toto</prenom></tns:bonjour></soap:Body></soap:Envelope>POST /api/helloworld/webservices.php HTTP/1.1
Pour information l'authentification fonctionne avec PHP et la requête qui fonctionne avec PHP est la suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 // On appelle le web service WebService mywebservice = new WebService(); // Définit une authentification BASIC CredentialCache myCredentials = new CredentialCache(); NetworkCredential netCred = new NetworkCredential("User1", "Pass1"); myCredentials.Add(new Uri(mywebservice.Url), "Basic", netCred); mywebservice.Credentials = myCredentials; // Définit la valeur de l'user agent mywebservice.UserAgent = ".NET Framework"; string retour = mywebservice.bonjour("Tata"); MessageBox.Show(retour, "Retour de l'API", MessageBoxButtons.OK, MessageBoxIcon.Information);
Merci encore pour votre aide.
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 POST /api/helloworld/webservices.php HTTP/1.0 Host: www.domaine.com:443 User-Agent: NuSOAP/0.9.5 (1.123) Content-Type: text/xml; charset=ISO-8859-1 SOAPAction: "https://www.domaine.com/api/helloworld/webservices.php?wsdl#bonjour" Authorization: Basic fFGFdGDFGGGFdfhllerGDSFGFDGDSFGksjfdsgk343gFGFG== Content-Length: 637 <?xml version="1.0" encoding="ISO-8859-1"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="https://www.domaine.com/api/helloworld/webservices.php?wsdl"> <SOAP-ENV:Body> <tns:bonjour xmlns:tns="https://www.domaine.com/api/helloworld/webservices.php?wsdl"> <prenom xsi:type="xsd:string">Tata</prenom> </tns:bonjour> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Partager