Se connecter au Service Web WCF à l'aide de Jquery et Soap-XML
J'ai un simple service web WCF j'ai essayé de me connecter avec jquery et SOAP-XML ( dataType: "xml" ) .mais quand j'ai envoyer ma demande j'obtiens un "BAD REQUEST Error 400" à partir de mon serveur.
voici mon SOAP-XML:
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> \
<soap:Header> \
<Action soap:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/IService/HelloWorld</Action> \
</soap:Header> \
<soap:Body> \
<HelloWorld xmlns="http://tempuri.org/"> \
</HelloWorld> \
</soap:Body> \
</soap:Envelope>';
et c'est mon $.Ajax :
var productServiceUrl = 'http://localhost:3523/Service.svc/HelloWorld';
$.ajax({
url: productServiceUrl,
type: "POST",
dataType: "xml",
data: soapMessage,
complete: endSaveProduct,
contentType: "text/xml; charset=\"utf-8\"",
async: true,
error: function (xhr, textStatus, errorThrown) {
alert(errorThrown);
}
});
et voici le Détail de la Demande et de la Responce (j'ai la trace dans Google Chrome):
Demande Hedear
POST /Service.svc/HelloWorld HTTP/1.1 Host: localhost:3523 Connection: keep-alive Content-Length: 550 Origin: http://localhost:3523 X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.15 Safari/535.2 Content-Type: text/xml; charset="UTF-8" Accept: application/xml, text/xml, */*; q=0.01 Referer: http://localhost:3523/WcfService.htm Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
et mon en-Tête de Réponse
HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 04 Jan 2012 14:56:06 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Length: 0
Connection: Close
Demande de la charge utile:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <soap:Header><Action soap:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/HelloWorld</Action> </soap:Header><soap:Body><HelloWorld xmlns="http://tempuri.org/"></HelloWorld></soap:Body> </soap:Envelope>
et si mon service web WCF:
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml)]
String HelloWorld();
- j'ai essayé avec ( .asmx) service web et il fonctionne correctement .mais quand je veux l'utiliser pour appeler un service web wcf retourner Bad Request(400)
Vous devez vous connecter pour publier un commentaire.
J'ai trouvé le chemin. J'utilise cette solution :
c'est mon interface de Service Web :
c'est mon impliment de cette fonction dans le service Web :
et voici le Script pour se connecter à Web WCF servise:
souviens de la WCF (
url: "Service.svc"
) est près de ma Page html.[WebGet(ResponseFormat = WebMessageFormat.Json)]
code du travail. Pourquoi donc?