WCF System.ServiceModel.Channels.ClientFramingDuplexSessionChannel打开错误

时间:2018-06-22 17:41:58

标签: c# .net wcf windows-services

我有一个小型的WCF服务和客户端应用程序,当我在同一系统上运行它们时,它们可以正常工作,但是当我在单独的系统上运行它们时,却立即出现System.ServiceModel.CommunicationException失败。轨迹指示上述通道打开错误。这里会发生什么?

以下是需要注意的事项:

  • 我正在Windows 7,.net 4.6.1上运行。
  • 我在VS 2017中以管理员身份在调试模式下运行客户端和服务
  • 我可以从客户端成功地在VS中“添加服务”。
  • 服务运行时,我可以从客户端ping端口。
  • 我正在使用net.tcp,但是更改为http不会改变结果。
  • 两个系统上的Windows防火墙均已关闭。
  • 两个系统上的Windows Defender均已关闭。
  • 两个系统上均未运行防病毒软件。
  • 在两个系统上都启用了端口共享。
  • 我尝试了许多绑定和行为设置的变体,但都没有改变。

跟踪查看器中的堆栈跟踪:

System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '23:49:59.9970000'.

System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
TestServiceClient.MyService.IMyService.IsRunning()
TestServiceClient.MyService.MyServiceClient.IsRunning()
TestServiceClient.Program.Main(String[] args)

最低级别的跟踪记录:

[TraceRecord] Severity  Warning
TraceIdentifier http://msdn.microsoft.com/en- 
US/library/System.ServiceModel.CommunicationObjectOpenFailed.aspx
Description Failed to open 
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel
AppDomain   TestServiceClient.exe
Source   System.ServiceModel.Channels.ClientFramingDuplexSessionChannel/41421720

服务端源和配置:

IMyService.cs

namespace TestService
{
    using System.ServiceModel;

    [ServiceContract]
    interface IMyService
    {
        [OperationContract]
        bool IsRunning();
    }
}

MyService.cs

namespace TestService
{
    public class MyService : IMyService
    {
        public bool IsRunning()
        {
            return true;
        }
    }
}

Program.cs

namespace TestService
{
    using System;
    using System.ServiceModel;

    class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(MyService)))
            {
                host.Credentials.WindowsAuthentication.AllowAnonymousLogons = true;
                host.Open();
                Console.WriteLine("Server Application started");
                Console.ReadKey();
                host.Close();
            }
        }
    }
}

app.config(仅服务模型节点)

<system.serviceModel>
<services>
  <service name="TestService.MyService" behaviorConfiguration="MyServiceBehavior">
    <endpoint
      address=""
      binding="netTcpBinding"
      contract="TestService.IMyService">
    </endpoint>
    <endpoint
      address="mex"
      binding="mexTcpBinding"
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:30001/MyService" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpGetEnabled="false" />
      <serviceThrottling maxConcurrentCalls="500" maxConcurrentInstances="100" maxConcurrentSessions="10000" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <netTcpBinding>
    <binding
      name="MyServiceBinding">
      <security mode="None"/>
    </binding>
  </netTcpBinding>
</bindings>
<diagnostics wmiProviderEnabled="true">
  <messageLogging
       logEntireMessage="true"
       logMalformedMessages="true"
       logMessagesAtServiceLevel="true"
       logMessagesAtTransportLevel="true"
       maxMessagesToLog="3000"
   />
</diagnostics>
</system.serviceModel>

客户端源和配置:

Program.cs

namespace TestServiceClient
{
    using System;
    using MyService;

    class Program
    {
        static void Main(string[] args)
        {
            var client = new MyServiceClient();
            bool success = client.IsRunning();
            Console.WriteLine("Success!");
            Console.ReadKey();
        }
    }
}

app.config(仅ServiceModel节点)

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IMyService" closeTimeout="23:50:00"
        openTimeout="23:50:00" receiveTimeout="23:50:00" sendTimeout="23:50:00"
        transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
        hostNameComparisonMode="StrongWildcard" listenBacklog="10"
        maxBufferPoolSize="524288000" maxBufferSize="655360000" maxConnections="10"
        maxReceivedMessageSize="655360000">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483646" maxArrayLength="2147483646"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="23:50:00"
          enabled="false" />
      <security mode="None">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="net.tcp://192.168.5.2:30001/MyService"
    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IMyService"
    contract="MyService.IMyService" name="NetTcpBinding_IMyService">
    <identity>
      <userPrincipalName value="SMP00-CTDI-PC1\CTDI" />
    </identity>
  </endpoint>
</client>
<diagnostics wmiProviderEnabled="true">
  <messageLogging
       logEntireMessage="true"
       logMalformedMessages="true"
       logMessagesAtServiceLevel="true"
       logMessagesAtTransportLevel="true"
       maxMessagesToLog="3000"
   />
</diagnostics>
</system.serviceModel>

0 个答案:

没有答案