代码之家  ›  专栏  ›  技术社区  ›  capdragon

无法处理具有操作“”的消息

  •  2
  • capdragon  · 技术社区  · 14 年前

    当我从JQuery调用wcfsoap服务时,有人能告诉我该怎么做来修复这个错误吗?

    错误:

    <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重建请求并添加soapactionhttp头部分,我会得到相同的错误,除了我给它的值。

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

    这是我的应用程序代码/目录服务.cs:

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

    [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>
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Ladislav Mrnka    14 年前

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

    你的jQuery问题。我只是在action book的jQuery中检查了$.ajax函数,我认为您需要定义函数来创建SOAPAction头,并在发送$.ajax之前将该函数分配给它。

    编辑:

    基于这个问题和您之前的问题:为什么要使用SOAP?看来你们是在自己开发服务和客户。你对使用肥皂有特别的要求吗?还是只是一些运动?从jQuery使用RESTful服务要容易得多。RESTful服务可以返回POX(纯旧XML)或JSON。