【问题标题】:The message with Action '' cannot be processed无法处理带有 Action '' 的消息
【发布时间】:2010-09-08 20:10:35
【问题描述】:

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

错误:

<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 标头部分,我会得到相同的错误,除了我给它的值。

这是我的 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:

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

这是我的 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 客户端代码:

    $.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 请求:

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

【问题讨论】:

    标签: jquery wcf soap


    【解决方案1】:

    您的 HelloWorld 方法中缺少 OperationContract 属性。比从 Fiddler 调用应该使用 SOAPAction http://miami.edu/ICatalogService/HelloWorld 如果它仍然不起作用,您可以在 OperationContract 属性中显式定义 Action 和 ReplyAction。

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

    编辑:

    基于这个问题和您之前的问题:您为什么要使用 SOAP?看起来您正在自己开发服务和客户端。您是否有使用 SOAP 的特定要求,或者只是一些练习?从 jQuery 使用 RESTful 服务要容易得多。 RESTful 服务可以返回 POX(普通旧 XML)或 JSON。

    【讨论】:

    • 非常感谢。要回答您的问题,是的,我很想使用 REST,但对 http 绑定有特定的 OGC 应用程序配置文件要求,这需要我使用 SOAP。
    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多