由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action '' 的消息 [英] The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher

查看:37
本文介绍了由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action '' 的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天以来我一直在尝试解决这个问题......只有在调用soap服务时才会出现此错误,其余一切正常.

I try to solve this since few days ... I get this error only when call soap service, in rest all ok.

我在客户端的配置(在服务中是一样的,只是没有客户端部分)

My config in client (in service is the same, only not have client section)

<system.serviceModel>
<client>
  <endpoint address="soap" binding="customHttpBinding" bindingConfiguration="MyCustomHttpBinding" name="Soap" contract="ServiceModel.IService" />
</client>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
  <serviceActivations>
    <add relativeAddress="Service.svc" service="ServiceModel.Service" />
  </serviceActivations>
</serviceHostingEnvironment>
<bindings>
  <customBinding>
    <binding name="MyCustomHttpBinding">
      <textMessageEncoding messageVersion="Soap12" />
      <context protectionLevel ="None"/>
      <httpTransport transferMode ="Buffered" />
    </binding>
  </customBinding>
  <webHttpBinding>
    <binding name="webHttpBindingSettings" closeTimeout="00:01:00" transferMode="Streamed" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="524288" maxReceivedMessageSize="654321">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="ServiceModel.Service" behaviorConfiguration="MetadataBehavior">
    <endpoint address="soap" binding="customBinding" bindingConfiguration="MyCustomHttpBinding" name="Soap" contract="ServiceModel.IService" />
    <endpoint address="rest" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingSettings" name="Json" contract="ServiceModel.IService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://dev.add.com/Service.svc/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MetadataBehavior">
      <serviceDebug includeExceptionDetailInFaults="true"  />
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="jsonBehavior">
      <webHttp automaticFormatSelectionEnabled="true" helpEnabled="true" />
    </behavior>
  </endpointBehaviors>
</behaviors>

我的服务

    [ServiceContract(Namespace = "ServiceModel")]
public interface IService
{
    [OperationContract]
    [WebInvoke()]
    GetInfoResponse GetRestData(GetInfoRequest message);

    [OperationContract]
    [WebInvoke()]
    GetInfoResponse GetSoapData(GetInfoRequest message);

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
    string Save(Stream message);
}

呼叫服务

            GetInfoRequest message = CheckedFields;
        string soap = @"<?xml version=""1.0"" encoding=""utf-8""?>
                <soap12:Envelope xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
                  <soap12:Header>
                    <Action soap12:mustUnderstand=""1"" xmlns=""http://www.w3.org/2005/08/addressing"">ServiceModel/IService/GetSoapData</Action>
                  </soap12:Header>
                <soap12:Body>
            <GetInfoRequest  xmlns=""ServiceModel"">
                <Data xmlns:d4p1=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/>
            </GetInfoRequest>
            </soap12:Body>
            </soap12:Envelope>";
        XmlSerializer serializer = new XmlSerializer(typeof(GetInfoRequest));
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://dev.add.renault.com/Service.svc/soap");
        MemoryStream stream1 = new MemoryStream();
        serializer.Serialize(stream1, message);
        stream1.Position = 0;
        StreamReader sr = new StreamReader(stream1);
        string t = sr.ReadToEnd();
        t = t.Remove(0, 22).Trim();
        t = string.Format(soap, t);
        ASCIIEncoding encoding = new ASCIIEncoding();
        request.Timeout = 99999999;
        request.ContentLength = t.Length;
        request.Method = "POST";
        request.ContentType = "application/soap+xml; charset=utf-8";
        request.Accept = "application/soap+xml; charset=utf-8";

        using (Stream stm = request.GetRequestStream())
        {
            using (StreamWriter stmw = new StreamWriter(stm))
            {
                stmw.Write(t);
            }
        }

        var response = (HttpWebResponse)request.GetResponse();
        var abc = new StreamReader(response.GetResponseStream());

堆栈跟踪

System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(Exception e, Message message)
System.ServiceModel.Dispatcher.ChannelHandler.ReplyFailure(RequestContext request, Message fault, String action, String reason, FaultCode code)
System.ServiceModel.Dispatcher.ChannelHandler.ReplyFailure(RequestContext request, FaultCode code, String reason, String action)
System.ServiceModel.Dispatcher.ChannelHandler.ReplyContractFilterDidNotMatch(RequestContext request)
System.ServiceModel.Dispatcher.ChannelHandler.EnsureChannelAndEndpoint(RequestContext request)
System.ServiceModel.Dispatcher.ChannelHandler.TryRetrievingInstanceContext(RequestContext request)
System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
System.Runtime.InputQueue`1.EnqueueAndDispatch(Item item, Boolean canDispatchOnThisThread)
System.Runtime.InputQueue`1.EnqueueAndDispatch(T item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
System.ServiceModel.Channels.SingletonChannelAcceptor`3.Enqueue(QueueItemType item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

推荐答案

问题是在配置中我使用 Soap12,但我使用 WebHttpRequest 发送的消息包含带有非 Soap12 元素的 Soap Header.

The problem was that in config I use Soap12 but message which I send using WebHttpRequest contains Soap Header with non Soap12 element.

这篇关于由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action '' 的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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