JQuery wcf call soap

Does anyone know that I can make a japery soap call for the wcf service?

My jQuery code:

$.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); } }); 

My data in 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> 

My C # code:

 [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); } } 

I get the following error from xhr.statusText:

uncaught exception: [Exception ... "Component return code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [NsIXMLHttpRequest.statusText]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame : 49 /75 / local // Test script.js :: anonymous :: line 22 "data: no]

Line 0

Edit # 1:

My request headers:

 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 

Answer:

 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 
+3
source share
1 answer

Take a look at jQuery.ajax () . It says:

error (jqXHR, textStatus, errorThrown)

Function called if the request fails. The function receives three arguments: the jqXHR object (in jQuery 1.4.x, XMLHttpRequest), a string describing the type of error that occurred, and an optional exception object if this happened. Possible values ​​for the second argument (other than zero) are timeout, error, abort, and parsererror. When an HTTP error occurs, errorThrown receives the text part of the HTTP status, for example, "Not Found" or "Internal Server Error". Starting with jQuery 1.5, the error parameter can take an array of functions. Each function will be called in turn. Note. This handler is not called for cross-domain script and JSONP requests. This is an Ajax event.

Your error is probably caused by an attempt to access the statusText, it is possible that there is no one available. Try adding two other arguments to your code and checking their contents.

Also, which browser are you using? There are some behavioral differences in how XmlHttpRequests is handled among different browsers, so trying in a few cases can help diagnose these things.

0
source

All Articles