从 wsdl 构造肥皂请求并使用 jquery 构建服务契约
我正在尝试使用 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)."
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)."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅最简单的 SOAP 示例
一个完整的例子。
你需要做的就是找出你的目标是什么。
SOAPAction、名称空间、元素名称和顺序、属性以及所有内容。
在尝试编写重现该消息所需的 Javascript 之前,最好能看到一个有效、有效的 SOAP 消息的示例。
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.
您想从 Javascript 谈论 SOAP 吗?太大胆了。
这并不是真正的答案,但请尝试使用wireshark和/或soapUI检查您的流量。如果您有一个可用的 SOAP 客户端,请运行它并查看它的作用,然后尝试复制它。
请注意,某些 SOAP 服务器将使用 HTTP 标头来路由操作 (
SOAPAction
)。错误信息让我怀疑这可能是问题所在?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?我相信您必须尝试使用 WebHTTPBinding,因为您正在尝试基于 REST 的客户端。
尝试寻找基于 REST 的实现,它最适合从 Javascript 调用。
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.