0

我正在尝试使用 jQuery 从 wcf Web 服务获取数据。我的jQuery代码如下:

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

我有一份服务合同:

[OperationContract]
String GetContainerByName(String _label);

[OperationContract]
String GetContainerByToken(Guid _Token);

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

我有一个 xsd 文件,我可以在 http://.svc/mex 访问它,其中包括

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

我传递给 jQuery 的数据是:

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>';

我需要访问 GetContainerByToken 方法。但我不断收到此错误:

"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)."
4

3 回答 3

2
于 2011-05-05T12:38:55.680 回答
1

您想从 Javascript 中讨论 SOAP 吗?那是胡说八道。

这不是一个真正的答案,但请尝试使用wireshark 和/或soapUI 检查您的流量。如果您有一个正常工作的 SOAP 客户端,请运行它并查看它的作用,然后尝试复制它。

请注意,某些 SOAP 服务器将使用 HTTP 标头来路由操作 ( SOAPAction)。错误信息让我怀疑这可能是问题所在?

于 2011-05-05T10:45:45.493 回答
0

我相信您必须尝试使用​​ WebHTTPBinding,因为您正在尝试基于 REST 的客户端。

尝试寻找最适合从 Javascript 调用的基于 REST 的实现。

于 2011-05-05T12:44:29.680 回答