协议异常Wcf

时间:2013-05-04 22:37:59

标签: wcf web-services

我想知道你是否能帮助解决wcf问题,这是我的web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--Diagnostics section, we will only catch error and warning in production-->

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Error, Warning">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="ITLocal.OlapWcfServiceBrowser2005">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Error, Warning">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="ITLocal.OlapWcfServiceBrowser2005">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <!--This is our path in the production server: D:\Sitios\ITLocal.OlapWcfServiceBrowser2005\Log\-->
      <add initializeData="C:\Users\tmxidsggutie\Desktop\ITLocal.OlapWcfServiceBrowser2005_web_tracelog.svclog" 
              type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
              name="ServiceModelTraceListener" 
              traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, Callstack">
        <filter type="" />
      </add>
      <add initializeData="C:\Users\tmxidsggutie\Desktop\ITLocal.OlapWcfServiceBrowser2005_web_messages.svclog" 
              type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
              name="ServiceModelMessageLoggingListener" 
              traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, Callstack">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483646" />
  </system.web>

  <!--For all the services we will aply the following service and endpoint behaviors-->

  <system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
      <endToEndTracing activityTracing="false" />
    </diagnostics>
    <behaviors>

      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
          <serviceTimeouts transactionTimeout="02:00:00" />
          <serviceDiscovery></serviceDiscovery>
        </behavior>
      </serviceBehaviors>

      <endpointBehaviors>
        <behavior>
          <endpointDiscovery enabled="true"></endpointDiscovery>
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />          
        </behavior>
      </endpointBehaviors>

    </behaviors>


    <!--All the FEMSA's clients are .net, so we will use the proprietary binary message encoding to reduce the message's size -->

    <bindings>
      <customBinding>
        <binding name="wsHttpBindingBynaryEncoding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
          <binaryMessageEncoding>
            <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880" />
          </binaryMessageEncoding>
          <httpTransport allowCookies="false" transferMode="Buffered" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646">
          </httpTransport>
        </binding>
      </customBinding>
    </bindings>

    <!-- In case you want to scale this service -->

    <standardEndpoints>
      <udpDiscoveryEndpoint>
        <standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryMode="Adhoc" discoveryVersion="WSDiscovery11" maxResponseDelay="00:00:10">
        </standardEndpoint>
      </udpDiscoveryEndpoint>


      <announcementEndpoint>
        <standardEndpoint name="UdpAnnouncementEndpoint" discoveryVersion="WSDiscovery11" />
      </announcementEndpoint>

    </standardEndpoints>

    <services>
      <service name="ITLocal.Analysis2005.Analysis2005">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8081/Analysis2005Browser.svc/"/>
          </baseAddresses>
        </host>
        <endpoint name="Rules" address="Rules" binding="customBinding" bindingConfiguration="wsHttpBindingBynaryEncoding" contract="ITLocal.Contracts.Olap.ISSASRulesContract"></endpoint>        
        <endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint" endpointConfiguration="adhocDiscoveryEndpointConfiguration" />
        <endpoint name="Mex" address="Mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

  </system.serviceModel>

  <system.webServer>
    <directoryBrowse enabled="true"/>
    <handlers>
      <remove name="svc-Integrated"/>
    </handlers>
  </system.webServer>

</configuration>

正如你所看到的那样,我正在追踪我的服务,tracelog和messagelog,我面临的问题是我得到协议异常,但只有在我的客户端添加服务引用时,所以如果我添加URI [http:// localhost:8081 / Analysis2005Browser.svc / mex]我在我的tracelog中得到了这个:

<Exception>
<ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>There is a problem with the XML that was received from the network. See inner exception for more details.</Message>
<StackTrace>
at System.Runtime.Diagnostics.EtwDiagnosticTrace.WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth)
at System.Runtime.Diagnostics.EtwDiagnosticTrace.ExceptionToTraceString(Exception exception, Int32 maxTraceStringLength)
at System.Runtime.Diagnostics.EtwDiagnosticTrace.GetSerializedPayload(Object source, TraceRecord traceRecord, Exception exception, Boolean getServiceReference)
at System.Runtime.TraceCore.ThrowingException(EtwDiagnosticTrace trace, String param0, String param1, Exception exception)
at System.Runtime.ExceptionTrace.TraceException[TException](TException exception, String eventSource)
at System.Runtime.ExceptionTrace.AsError(Exception exception)
at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result)
at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result)
at System.Runtime.AsyncResult.SyncContinue(IAsyncResult result)
at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult..ctor(ReplyChannelAcceptor acceptor, Action dequeuedCallback, HttpPipeline pipeline, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync()
at System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state)
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---&gt; System.Xml.XmlException: The body of the message cannot be read because it is empty.
   --- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<Exception>
<ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The body of the message cannot be read because it is empty.</Message>
<StackTrace>
at System.Runtime.Diagnostics.EtwDiagnosticTrace.WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth)
at System.Runtime.Diagnostics.EtwDiagnosticTrace.GetInnerException(Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth)
at System.Runtime.Diagnostics.EtwDiagnosticTrace.WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth)
at System.Runtime.Diagnostics.EtwDiagnosticTrace.ExceptionToTraceString(Exception exception, Int32 maxTraceStringLength)
at System.Runtime.Diagnostics.EtwDiagnosticTrace.GetSerializedPayload(Object source, TraceRecord traceRecord, Exception exception, Boolean getServiceReference)
at System.Runtime.TraceCore.ThrowingException(EtwDiagnosticTrace trace, String param0, String param1, Exception exception)
at System.Runtime.ExceptionTrace.TraceException[TException](TException exception, String eventSource)
at System.Runtime.ExceptionTrace.AsError(Exception exception)
at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result)
at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result)
at System.Runtime.AsyncResult.SyncContinue(IAsyncResult result)
at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult..ctor(ReplyChannelAcceptor acceptor, Action dequeuedCallback, HttpPipeline pipeline, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state)
at System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync()
at System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state)
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.Xml.XmlException: The body of the message cannot be read because it is empty.</ExceptionString>
</Exception>
</InnerException>
</Exception>

我将此异常作为警告,因为我可以毫无问题地调用我的wcf服务的方法,奇怪的是使用wcf测试客户端,当我添加上面相同的URI时,我没有得到这个例外。另一个奇怪的事情是,如果我为这个更改uri [http:// localhost:8081 / Analysis2005Browser.svc /],我会得到一个不同的异常:找不到端点或SOAP操作(在这种情况下,我得到了这个使用wcf测试客户端或添加服务引用的svc tracelog中的异常:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>262155</EventID><Type>3</Type><SubType Name="Error">0</SubType><Level>2</Level><TimeCreated SystemTime="2013-05-04T22:09:47.8030567Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="w3wp" ProcessID="3596" ThreadID="26" /><Channel /><Computer>FEMXDMSCONTR1A</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"><TraceIdentifier>http://msdn.microsoft.com/es-MX/library/System.ServiceModel.Channels.HttpChannelMessageReceiveFailed.aspx</TraceIdentifier><Description>Failed to lookup a channel to receive an incoming message. Either the endpoint or the SOAP action was not found.</Description><AppDomain>/LM/W3SVC/6/ROOT-1-130121789629535720</AppDomain><Source>System.ServiceModel.Activation.HostedHttpTransportManager/43776817</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/StringTraceRecord"><IsRecycling>False</IsRecycling></ExtendedData></TraceRecord></DataItem></TraceData><System.Diagnostics xmlns="http://schemas.microsoft.com/2004/08/System.Diagnostics"><LogicalOperationStack></LogicalOperationStack><Timestamp>7122556802571</Timestamp><Callstack>   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at System.Diagnostics.TraceEventCache.get_Callstack()
   at System.Diagnostics.XmlWriterTraceListener.WriteFooter(TraceEventCache eventCache)
   at System.Diagnostics.XmlWriterTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   at System.Diagnostics.TraceSource.TraceData(TraceEventType eventType, Int32 id, Object data)
   at System.ServiceModel.Diagnostics.LegacyDiagnosticTrace.TraceEvent(TraceEventType type, Int32 code, String msdnTraceCode, String description, TraceRecord trace, Exception exception, Object source)
   at System.ServiceModel.Diagnostics.TraceUtility.TraceEvent(TraceEventType severity, Int32 traceCode, String traceDescription, TraceRecord extendedData, Object source, Exception exception)
   at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
   at System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)
   at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</Callstack></System.Diagnostics></ApplicationData></E2ETraceEvent>

我做错了什么,正如我之前所说,我可以毫无问题地调用我的服务操作但是为什么我会得到这些例外... ????

另外我注意到在消息日志中使用mex地址时,我得到了这个(双mex):

<MessageLogTraceRecord>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1" xmlns:a="http://www.w3.org/2005/08/addressing">http://schemas.xmlsoap.org/ws/2004/09/transfer/Get</a:Action>
<a:MessageID xmlns:a="http://www.w3.org/2005/08/addressing">urn:uuid:b60bf2b8-f798-471f-a9da-295168061277</a:MessageID>
<a:ReplyTo xmlns:a="http://www.w3.org/2005/08/addressing">
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1" xmlns:a="http://www.w3.org/2005/08/addressing">http://localhost:8081/Analysis2005Browser.svc/mex/mex</a:To>
</s:Header>
</s:Envelope>
</MessageLogTraceRecord>

谢谢你的建议。我正在使用.NET framework 4.5。

0 个答案:

没有答案