2011-01-06 161 views
3

任何人都知道我可以做一个wcf服务的jQuery肥皂呼叫?jquery wcf肥皂呼叫失败

我的jQuery代码:

$.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> 

我的C#代码:

[ServiceContract(Namespace = "http://temp.org/test/")] 
public interface IOrder 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST", 
       BodyStyle = WebMessageBodyStyle.Wrapped, 
       ResponseFormat = WebMessageFormat.Xml, 
       RequestFormat = WebMessageFormat.Xml)] 

    string HelloWorld(string name); 

} 
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] 
public class OrderingService : IOrder 
{ 
    public string HelloWorld(string name) 
    { 
     return String.Format("Hello {0}", name); 
    } 

} 

我从xhr.statusText出现以下错误:

未捕获的异常:[异常... “组件返回失败代码: 0x80040111(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.statusText]” nsresult: “0x80040111 (NS_ERROR_NOT_AVAILABLE)” 位置: “JS帧:: http://localhost:49758/TestClient/js/script.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 
+0

需要知道您在服务器上使用的WCF绑定和端点信息。我建议使用工作的.net客户端应用程序跟踪请求/回复,然后复制该有效内容和标题。 – alexdej 2011-01-06 22:50:45

回答

0

看看在jQuery.ajax() API文档。它说:

错误(jqXHR,textStatus,errorThrown)

的函数,如果请求失败被调用。该函数接收三个参数:jqXHR(在jQuery 1.4.x中,XMLHttpRequest)对象,一个描述发生的错误类型的字符串以及一个可选的异常对象(如果发生的话)。第二个参数的可能值(除了null)是“timeout”,“error”,“abort”和“parsererror”。发生HTTP错误时,errorThrown会收到HTTP状态的文本部分,例如“未找到”或“内部服务器错误”。从jQuery 1.5开始,错误设置可以接受一组函数。每个函数都会依次调用。注意:此处理程序不针对跨域脚本和JSONP请求进行调用。这是一个Ajax事件。

您的错误可能是由于尝试访问statusText而引发的,有可能没有可用的错误。尝试将其他两个参数添加到您的代码并检查其内容。

此外,您正在使用哪种浏览器?在各种浏览器中处理XmlHttpRequests的方式存在一些行为差异,因此尝试使用多个浏览器有时可以帮助诊断这些事情。