Javascript jquery wcf soap调用失败
有人知道我可以对wcf服务进行jquery soap调用吗 我的JQuery代码:Javascript jquery wcf soap调用失败,javascript,.net,jquery,wcf,soap,Javascript,.net,Jquery,Wcf,Soap,有人知道我可以对wcf服务进行jquery soap调用吗 我的JQuery代码: $.ajax({ url: "http://localhost/oseop/orderingservice.svc/HelloWorld", data: $("#txtTestRequest").val(), type: "POST", processData: true, contentType: "application/xml; charset=utf-8",
$.ajax({
url: "http://localhost/oseop/orderingservice.svc/HelloWorld",
data: $("#txtTestRequest").val(),
type: "POST",
processData: true,
contentType: "application/xml; charset=utf-8",
timeout: 10000,
dataType: "xml",
beforeSend: function (xhr) {
xhr.setRequestHeader("SOAPAction", "HelloWorld");
},
success: function (xml) {
console.log("Sucess");
console.log(xml);
},
error: function (xhr) {
console.log(xhr.statusText);
}
});
txtTextRequest中的我的数据:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:49720/OrderingServices/OrderingService.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://temp.org/test/IOrder/HelloWorld</Action>
</s:Header>
<soap:Body>
<HelloWorld xmlns="http://temp.org/test/">
<name>my name is earl</name>
</HelloWorld>
</soap:Body>
</soap:Envelope>
我从xhr.statusText中得到以下错误:
未捕获异常:[异常。。。
“组件返回故障代码:
0x80040111(NS\u错误\u不可用)
[nsIXMLHttpRequest.statusText]“
nsresult:“0x80040111
(NS\u错误\u不可用)“位置:
“JS框架::
::匿名::第22行“数据:否]
第0行
编辑#1:
我的请求标题:
OPTIONS http://localhost/oseop/orderingservice.svc/HelloWorld HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: http://localhost:49758
Access-Control-Request-Method: POST
Access-Control-Request-Headers: soapaction
答复:
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Fri, 07 Jan 2011 14:00:53 GMT
Content-Length: 0
看看API文档。它说:
错误(jqXHR、textStatus、errorshown)
请求失败时要调用的函数。该函数接收三个参数:jqXHR(在jQuery 1.4.x中,XMLHttpRequest)对象、描述发生的错误类型的字符串和可选的异常对象(如果发生)。第二个参数(除null外)的可能值为“timeout”、“error”、“abort”和“parserror”。当HTTP错误发生时,ErrorSprown将接收HTTP状态的文本部分,例如“未找到”或“内部服务器错误”。从jQuery 1.5开始,错误设置可以接受函数数组。每个函数将依次调用。注意:跨域脚本和JSONP请求不调用此处理程序。这是一个Ajax事件
您的错误可能是由于尝试访问statusText而引发的,可能没有可用的statusText。尝试将其他两个参数添加到代码中并检查其内容
另外,您正在使用哪个浏览器?不同浏览器处理XmlHttpRequests的方式存在一些行为上的差异,因此在多个浏览器中进行尝试有时有助于诊断这些问题。需要了解服务器上使用的WCF绑定和端点信息。我建议使用运行中的.net客户端应用程序跟踪请求/回复,然后复制有效负载&headers.added headers。这就是你要找的吗?
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Fri, 07 Jan 2011 14:00:53 GMT
Content-Length: 0