0

I am trying to get data from a wcf web service using jQuery. My jQuery code is as follows:

                   jQuery.ajax({
                    type: "POST",
                    url: serviceWebPath,
                    data: data,
                    contentType: "text/xml; charset=utf-8",
                    dataType: "json",
                    success: function (data) { alert (data); },
                    error: _errorHandler
                    });

I have a service contract:

[OperationContract]
String GetContainerByName(String _label);

[OperationContract]
String GetContainerByToken(Guid _Token);

[OperationContract]
void SetContainer(Guid securityToken, String _Content);

I have an xsd file which I can access at http://.svc/mex and which includes

<wsdl:operation name="GetContainerByToken">
  <soap:operation soapAction="http://tempuri.org/IProxyShareContextContract/GetContainerByToken" style="document" /> 
 <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
 <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>

The data I pass to jQuery is :

var data = '<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/soap/envelope/"><soap:Body><GetContainerByToken><label>' + clientTokenSecuritySManager + '</label></GetContainerByToken></soap:Body></soap:Envelope>';

I need to access the GetContainerByToken method. But I keep on getting this error :

"The message with Action '' cannot be processed at the receiver, 
due to a ContractFilter mismatch at the EndpointDispatcher. This
may be because of either a contract mismatch (mismatched Actions
between sender and receiver) or a binding/security mismatch between
the sender and the receiver.  Check that sender and receiver have
the same contract and the same binding (including security requirements,
e.g. Message, Transport, None)."
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59

3 Answers3

2

See Simplest SOAP example for a full example.

What you need to do is find out what target you are aiming for. The SOAPAction, the namespaces, the element names and order, the attributes, and everything.

It would be good to see an example of a valid, working SOAP message, before trying to craft the Javascript necessary to reproduce it.

Community
  • 1
  • 1
Cheeso
  • 189,189
  • 101
  • 473
  • 713
1

You want to talk SOAP from Javascript? That's ballsy.

This is not really an answer, but try inspecting your traffic with wireshark and/or soapUI. If you have a working SOAP client, run that and look at what it does, then try to replicate that.

Note that some SOAP servers will use HTTP-headers for routing the action (SOAPAction). The error message leads me to suspect that this may be the problem?

troelskn
  • 115,121
  • 27
  • 131
  • 155
  • Ok well I added "SOAPAction : GetContainerByToken" to the headers, and now the erro message is exactly the same, except that the quotes now say 'GetContainerByToken'. A step forward though. Thanks! – Tom Macdonald May 05 '11 at 10:57
  • Ok it turns out, the right header wasn't just GetContainerByToken, but http://tempuri.org/IProxyShareContextContract/GetContainerByToken I can get a response now! Cool, thanks! – Tom Macdonald May 05 '11 at 12:58
  • The soapUI tip was brilliant, btw! – Tom Macdonald May 13 '11 at 14:04
0

I belive that you have to try using WebHTTPBinding since you are trying out a REST based client.

Try to look for REST based implementation, which is best suited for being called from Javascript.

SaravananArumugam
  • 3,680
  • 6
  • 33
  • 45