Service Web - C#/PHP - Problème d'entête (User-Agent)
Bonjour à tous,
Contexte :
J'ai créé un service web sur un serveur PHP (.php + wsdl) qui interrogé depuis mon client c# doit renvoyer un tableau.
J'ai fait l'importation du wsdl en tant que Service Références.
L'accès au serveur requiert une authentification basic pour l'interrogation du service web.
Le client est dans un projet Console Application, j'ai trouvé cela plus simple pour le développement mais à terme le client sera transféré sur un site web utilisant le même langage.
Problème :
J'ai une erreur du cotés du client.
Citation:
The remote server returned an unexpected response: (400) Bad Request.
J'ai une erreur aussi du coté serveur.
Citation:
[Fri Jun 07 12:52:35 2013] [error] [client 000.000.000.000] ModSecurity: Access denied with code 403 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS.
[file "/etc/apache2/mod-security/modsecurity_crs_21_protocol_anomalies.conf"] [line "48"] [id "960009"] [msg "Request Missing a User Agent Header"] [severity "WARNING"]
[tag "PROTOCOL_VIOLATION/MISSING_HEADER"] [hostname "www.test.fr"]
[uri "/service.php"] [unique_id "TbG7cCxq24cCCVV"]
Je n'ai pas trouvé le moyen de rajouter un user-agent dans le header de ma requête.
Voici les fichiers du client si le cela peut vous aidez.
.cs :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| static void Main(string[] args)
{
BasicHttpBinding binding = new BasicHttpBinding();
AnalysesServiceClient Analyse = new AnalysesServiceClient();
Analyse[] tab = new Analyse[100];
Analyse.ClientCredentials.UserName.UserName = "login";
Analyse.ClientCredentials.UserName.Password = "pwd";
tab = Analyse.getAnalyses(12, 24);
foreach (Analyse A in tab)
{
Console.Write(A._dateAnalyse + " ");
Console.Write(A._typeAnalyse + " ");
Console.Write(A._idAnalyse + " ");
Console.WriteLine();
}
Console.ReadLine();
}
} |
app.config :
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
| <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Analyses" maxBufferSize="999999"
maxReceivedMessageSize="999999" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic">
</transport>
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.test.fr/service.php"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Analyses"
contract="Analyses.AnalysesService" name="BasicHttpBinding_Analyses" >
</endpoint>
</client>
</system.serviceModel>
</configuration> |
WSDL :
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
| <?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions
targetNamespace="http://www.test.fr/"
xmlns:tns="http://www.test.fr/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<wsdl:types>
<xs:schema targetNamespace="http://www.test.fr/" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:complexType name = "Analyse">
<xsd:all>
<xs:element name="_typeAnalyse" type="xs:string"/>
<xs:element name="_idAnalyse" type="xs:int"/>
<xs:element name="_dateAnalyse" type="xs:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="TabAnalyses">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="DescripAnalyse" nillable="true" type="tns:Analyse" />
</xsd:sequence>
</xsd:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getAnalysesRequest">
<wsdl:part name="codeAgroDistri" type="xs:int"/>
<wsdl:part name="codeadheexploit" type="xs:int"/>
</wsdl:message>
<wsdl:message name="getAnalysesResponse">
<wsdl:part name="ListeAnalyses" type="tns:TabAnalyses"/>
</wsdl:message>
<wsdl:portType name= "AnalysesService">
<wsdl:operation name= "getAnalyses">
<wsdl:input message="tns:getAnalysesRequest"/>
<wsdl:output message="tns:getAnalysesResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_Analyses" type="tns:AnalysesService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getAnalyses">
<soap:operation soapAction="urn:#http://www.test.fr/getAnalyses"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port name="BasicHttpBinding_Analyses" binding="tns:BasicHttpBinding_Analyses">
<soap:address location="http://www.test.fr/service.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions> |
Je reste à votre disposition pour répondre à vos questions.
Merci.
Cordialement Skyvard