Hello! I get the ID from the web page using the following jquery.SOAP script:

$(document).ready(function () { $('tr').click(function () { id = $(this).attr('id'); $.soap({ url: "http://localhost:8123/C_M_Service/", method: "OrdersByPassport", SOAPAction: "http://localhost:8123/C_M_Service/OrdersByPassport", soap11: true, data: '<passport>'+ id + '</passport>', error: function (soapresponse) { alert("Oh no is error: " + soapresponse.toString()); }, success: function (result) { alert("OK " + result.toString()); } }); }); 

});

The script calls the Operation Contract of the WCF service:

 [OperationContract(Action = "http://localhost:8123/C_M_Service/OrdersByPassport")] [WebGet(RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped)] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped)] string OrdersByPassport(int passport); 

...

 public string OrdersByPassport(int passport) { Repository repository = new Repository(); Query_result qr = new Query_result(); qr.data = repository.GetOrdersByPassport(passport); return (qr.ToString()); } 

When using the WCF test client, there are no problems. When the web page interacts with the service, an error occurs when transferring data from the service: "Error deserializing the request message body for the operation" OrdersByPassport. " // C_M_Service ". Found the node type" Element "with the name" passport "and the namespace" "". Please help with this problem.

    1 answer 1

    You do not send data in the format in which the service expects. The format that the service expects is on the description page that opens when the project is launched in the browser (if you host the service in iis). You will most likely have it available at the link of the form http: // localhost: 8123 / C_M_Service / OrdersByPassport? Wsdl .

    Now the service is waiting for something like

     <OrdersByPassport xmlns="http://C_M_Service"> тут что-то еще </OrdersByPassport> 

    and you send him something like

     <passport>42<passport> 

    You must send the request exactly in the form in which the service is waiting for it.

    Take any http debugger (for example, fiddler), or at least the dev console network browser tools.

    Write down the request from the test client (or better, from the test form from the service help page in the browser). And then change your sending code until the request format completely matches.

    • Thanks for the answer! The service works with SOAP data (spelled out in the configuration file). Tried to do as you suggest, before: sent from the service, what the test client issued at the output. The error remained. The service's host is a Windows service, I use fiddler, and it issues the same as the alert in the script. I can not understand where the element "passport" in the response of the service, because it is input data. It is not included in the Data Contract. WSDL opened, but do not really understand what to look here. - AN90
    • @ AN90 Record the request from the test client and try to send an exact copy of it, up to the namespace. Your service now crashes because you OrdersByPassport n't send the OrdersByPassport element OrdersByPassport it. And judging by the code - yes, you do not send. - PashaPash
    • Indeed, this item is not sent. And it is not sent even when I write it in the data in the script. Is this some kind of jQuery.SOAP oddity or something I don’t understand? In general, the message that forms the jQuery.SOAP is significantly different from the message of the test client. - AN90
    • Understood. The modified script rebooted only after restarting the browser. - AN90