2011-10-06 70 views
2

我試圖在幾天內解決這個問題......只有在呼叫肥皂服務時,我纔會得到此錯誤,在休息時一切正常。由於EndpointDispatcher上的ContractFilter不匹配,無法在接收方處理帶有Action''的消息

我在客戶端配置(服務是一樣的,只是沒有客戶端單元)

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

回答

4

問題是在配置中我使用Soap12,但是使用WebHttpRequest發送的消息包含Soap Header和非Soap12元素。

0

你已經在你的請求字符串硬編碼的行動是錯誤的。默認操作可能是ServiceModel/IService1/GetSoapData。

[我強烈建議使用標準的WCF客戶端來測試你的SOAP服務。如果您需要檢查生成的實際XML,則可以打開診斷和日誌消息。 WCF提供了很多功能來控制它收到/發送的消息。除非你理解你正在使用的所有配置開關的實現,否則很難預測需要什麼消息更改。]

+0

我添加堆棧跟蹤;)也許它有助於... ... – netmajor

相關問題