Web Service - C# Client and Apache Server - Error HTTP 400 Bad Request

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I write here because Im working to transport a PHP webservice client to C# (VS2010).
Project are in Framework4 but the web service was added in VS2010 like a web service compatible with Framework2 (Web Reference with WSDL).
Actually Im working only on a classical webservice (a Helloworld test).
With the client C# I have no problem I send a text to the web service and the web service return correctly the text. I have no error in Apache Server.

If I active the basic authentification in the .htaccess in apache server (host the webservice server), so in the client C# I have this error :
Exception : WebException <br/>
Bad Request with state HTTP 400 : Bad Request.

In Apache error log I see this line :


<div style="color:black; background-color:white
<pre>[Thu Feb 02 23:52:06 2012] [error] [client XX.XX.XX.XX] Invalid URI in request
<span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue utf-8<span style="color:black "<span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 soap<span style="color:blue :<span style="color:#a31515 Envelope <span style="color:red xmlns:soap<span style="color:blue =<span style="color:black "<span style="color:blue http://schemas.xmlsoap.org/soap/envelope/<span style="color:black " <span style="color:red xmlns:soapenc<span style="color:blue =<span style="color:black "<span style="color:blue http://schemas.xmlsoap.org/soap/encoding/<span style="color:black " <span style="color:red <br/>xmlns:tns<span style="color:blue =<span style="color:black "<span style="color:blue https://www.domaine.com/api/helloworld/webservices.php?wsdl<span style="color:black " <br/><span style="color:red xmlns:types<span style="color:blue =<span style="color:black "<span style="color:blue https://www.domaine.com/api/helloworld/webservices.php?wsdl/encodedTypes<span style="color:black " <br/><span style="color:red xmlns:xsi<span style="color:blue =<span style="color:black "<span style="color:blue http://www.w3.org/2001/XMLSchema-instance<span style="color:black " <span style="color:red xmlns:xsd<span style="color:blue =<span style="color:black "<span style="color:blue http://www.w3.org/2001/XMLSchema<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 soap<span style="color:blue :<span style="color:#a31515 Body <span style="color:red soap:encodingStyle<span style="color:blue =<span style="color:black "<span style="color:blue http://schemas.xmlsoap.org/soap/encoding/<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 tns<span style="color:blue :<span style="color:#a31515 bonjour<span style="color:blue ><span style="color:blue <<span style="color:#a31515 prenom <span style="color:red xsi:type<span style="color:blue =<span style="color:black "<span style="color:blue xsd:string<span style="color:black "<span style="color:blue >Toto<span style="color:blue </<span style="color:#a31515 prenom<span style="color:blue ><span style="color:blue </<span style="color:#a31515 tns<span style="color:blue :<span style="color:#a31515 bonjour<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 soap<span style="color:blue :<span style="color:#a31515 Body<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 soap<span style="color:blue :<span style="color:#a31515 Envelope<span style="color:blue >
POST /api/helloworld/webservices.php HTTP/1.1
[/code]

<br/>



The code of C# Client are :

<div style="color:black; background-color:white
<pre><span style="color:green // We create the webservice
WebService mywebservice = <span style="color:blue new WebService();

<span style="color:green // We define BASIC Authentication
CredentialCache myCredentials = <span style="color:blue new CredentialCache();
NetworkCredential netCred = <span style="color:blue new NetworkCredential(<span style="color:#a31515 "User1", <span style="color:#a31515 "Pass1");
myCredentials.Add(<span style="color:blue new Uri(mywebservice.Url), <span style="color:#a31515 "Basic", netCred);
mywebservice.Credentials = myCredentials;

<span style="color:green // We define the UserAgent
mywebservice.UserAgent = <span style="color:#a31515 ".NET Framework";<span style="color:green <br/><br/>// We call the function of webservice<br/>string retour = mywebservice.bonjour("Tata");<br/><br/>// We show the return<br/>MessageBox.Show(retour, "Retour de lAPI", MessageBoxButtons.OK, MessageBoxIcon.Information);
[/code]


With the client writing in PHP this working fine.<br/>
This is the PHP client webservice request working fine (for compare with C# client request XML) :

<div style="color:black; background-color:white
<pre>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

<span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue ISO-8859-1<span style="color:black "<span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 SOAP-ENV<span style="color:blue :<span style="color:#a31515 Envelope <span style="color:red SOAP-ENV:encodingStyle<span style="color:blue =<span style="color:black "<span style="color:blue http://schemas.xmlsoap.org/soap/encoding/<span style="color:black "<br/> <span style="color:red xmlns:SOAP-ENV<span style="color:blue =<span style="color:black "<span style="color:blue http://schemas.xmlsoap.org/soap/envelope/<span style="color:black " <span style="color:red xmlns:xsd<span style="color:blue =<span style="color:black "<span style="color:blue http://www.w3.org/2001/XMLSchema<span style="color:black " <span style="color:red <br/>xmlns:xsi<span style="color:blue =<span style="color:black "<span style="color:blue http://www.w3.org/2001/XMLSchema-instance<span style="color:black " <span style="color:red xmlns:SOAP-ENC<span style="color:blue =<span style="color:black "<span style="color:blue http://schemas.xmlsoap.org/soap/encoding/<span style="color:black "<br/> <span style="color:red xmlns:tns<span style="color:blue =<span style="color:black "<span style="color:blue https://www.domaine.com/api/helloworld/webservices.php?wsdl<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 SOAP-ENV<span style="color:blue :<span style="color:#a31515 Body<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 tns<span style="color:blue :<span style="color:#a31515 bonjour <span style="color:red xmlns:tns<span style="color:blue =<span style="color:black "<span style="color:blue https://www.domaine.com/api/helloworld/webservices.php?wsdl<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 prenom <span style="color:red xsi:type<span style="color:blue =<span style="color:black "<span style="color:blue xsd:string<span style="color:black "<span style="color:blue >Tata<span style="color:blue </<span style="color:#a31515 prenom<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 tns<span style="color:blue :<span style="color:#a31515 bonjour<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 SOAP-ENV<span style="color:blue :<span style="color:#a31515 Body<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 SOAP-ENV<span style="color:blue :<span style="color:#a31515 Envelope<span style="color:blue >
[/code]

<br/>
<br/>

This is the .htaccess

<div style="color:black; background-color:white
<pre><span style="color:green # Dont show directory listings for URLs which map to a directory.
Options -Indexes

<span style="color:green # Se logue avec un compte AD
AuthType Basic
AuthBasicProvider ldap
AuthName <span style="color:#a31515 "Acces au webservice"
AuthLDAPURL ldap:<span style="color:green //127.0.0.1:389/ou=clients,dc=domaine,dc=com?mail
Require valid-user
[/code]

<br/>
<br/>

If I delete the .htaccess file everything its working.<br/>

Thank you very much for your help.

<br/>

View the full article
 
Back
Top