无法处理带有动作“"的消息 [英] The message with Action '' cannot be processed

查看:81
本文介绍了无法处理带有动作“"的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从JQuery调用WCF SOAP服务时,谁能告诉我如何解决此错误?

Can anyone tell me what i can do to fix this error when i call a WCF SOAP service from JQuery?

错误:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">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).</faultstring></s:Fault></s:Body></s:Envelope>

如果我使用Fiddler重建请求并添加SOAPAction http标头部分,则除了给出的值外,我会遇到相同的错误.

If i use Fiddler to rebuild the request and add the SOAPAction http header portion, i get the same error except with the value i gave it.

这是我的web.config:

Here is my web.config:

<configuration>
<system.web>
    <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="soapBinding">
                <security mode="None">
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <services>
        <service name="CatalogService" behaviorConfiguration="defaultBehavior">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="ICatalogService"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="defaultBehavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

这是我的App_Code/CatalogService.cs:

Here is my App_Code/CatalogService.cs:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]  public class CatalogService : ICatalogService  {
public string HelloWorld(string name){
    return String.Format("Hello {0}", name);}}

这是我的App_Code/CatalogIService.cs:

Here is my App_Code/CatalogIService.cs:

[ServiceContract(Namespace = "http://miami.edu/")]  public interface ICatalogService {
[WebInvoke(Method = "POST",
             BodyStyle = WebMessageBodyStyle.Wrapped,
             ResponseFormat = WebMessageFormat.Xml,
             RequestFormat = WebMessageFormat.Xml)]
string HelloWorld(string name);}

这是我的jQuery客户端代码:

Here is my jQuery client code:

    $.ajax({
type: 'POST',
url: 'http://localhost/csw/service.svc/soap',
data: request,
contentType: 'text/xml; charset=utf-8',
dataType: 'text',
success: function (result) {
    console.log(result);

    $("#result").text(result);
    //result.responseXML
    //result.responseText
},
error: function (message) {
    console.log(message);
    alert("error has occured" + message);
}});

这是我的SOAP请求:

Here is my SOAP request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>  <HelloWorld xmlns="http://cstars.miami.edu/CatalogService">  <name>CarlosK</name>  </HelloWorld>  </s:Body>  </s:Envelope>

推荐答案

您在HelloWorld方法中缺少OperationContract属性.比从Fiddler进行呼叫更应该与SOAPAction一起使用 http://miami.edu/ICatalogService/HelloWorld 如果仍然无法使用,则可以在OperationContract属性中显式定义Action和ReplyAction.

You are missing OperationContract attribute on your HelloWorld method. Than calling from Fiddler should work with SOAPAction http://miami.edu/ICatalogService/HelloWorld If it still doesn't work you can explicitly define Action and ReplyAction in OperationContract attribute.

您的jQuery问题.我只是在操作手册中检查了jQuery中的$ .ajax函数,我认为您需要定义函数来创建SOAPAction标头,然后将该函数分配给$ .ajax中的beforeSend.

To your jQuery problem. I just check $.ajax function in jQuery in action book and I think you need to define function to create SOAPAction header and assign that function to beforeSend in $.ajax.

基于此问题和您先前的问题:为什么要使用SOAP?看来您自己正在开发服务和客户端.您对使用SOAP有特定要求吗?还是仅是一些专业知识?使用jQuery的RESTful服务要容易得多. RESTful服务可以返回POX(普通的旧XML)或JSON.

Based on this question and your previous question: Why do you want to use SOAP? It looks like you are developing service and client by yourselves. Do you have specific requirement to use SOAP or is it only some excercise? It is much easier to consume RESTful service from jQuery. RESTful service can return POX (plain old XML) or JSON.

这篇关于无法处理带有动作“"的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆