从另一个WCF服务调用WCF服务会导致错误

时间:2016-11-23 07:11:24

标签: c# .net wcf windows-services

我有一个托管在Service1上的Windows服务中的WCF服务(Server1),Service1使用另一个托管在另一个中的WCF服务(Service2Server2上的Windows服务,当我从Service1调用WCF test client的方法时,出现以下错误:

  

套接字连接已中止。这可能是由于处理消息的错误或远程主机超出接收超时或基础网络资源问题引起的。本地套接字超时为'00:14:59.9850000'。

     

服务器堆栈跟踪:      在System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息回复,MessageFault错误,字符串操作,MessageVersion版本,FaultConverter faultConverter)      在System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc& rpc)      在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操作)      在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

     

在[0]处重新抛出异常:      在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)      在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type)      在IService1.GetHeatInstructionByOrderItemId(Int32 orderItemId)      at Service1Client.GetHeatInstructionByOrderItemId(Int32 orderItemId)

但是当Service2放在Server1上时(Server1中的2个服务),该方法会毫无错误地运行。

Service2配置:

<?xml version="1.0"?>
<configuration>
<system.web>
   <compilation debug="true"/>
</system.web>
<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBindingEndpointConfig">
      <security mode="Transport" />
    </binding>
    <binding name="NetTcpBindingEndpoint" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
      hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
      maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<services>
  <service name="MeltshopServiceLibrary.Service2">
    <endpoint address="" binding="netTcpBinding" 
     bindingConfiguration="NetTcpBindingEndpointConfig"
      name="NetTcpBindingEndpoint" contract="MeltshopServiceLibrary.IService2" />
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
      name="mexTcpBidingEndpoint" 
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://Server2:1531/Service2" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
 <add name="MeltshopConnection" providerName="System.Data.OracleClient" connectionString="Data Source=******;Persist Security Info=True;User ID=*****;password =****** "/>
 <add name="KosarConnection" providerName="System.Data.OracleClient" connectionString="Data Source=*****;Persist Security Info=True;User ID=******;password =*******"/>
</connectionStrings>
</configuration>

这是Service1配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<client>
  <endpoint address="net.tcp://Server2:1531/Service2" binding="netTcpBinding"
     bindingConfiguration="NetTcpBindingEndpointConfig"  contract="MyServiceReference2.IService2"
     name="NetTcpBindingEndpoint3" >
      <identity>
      <dns value="Server2" />
    </identity>
  </endpoint>
</client>

<bindings>
  <netTcpBinding>
    <binding name="NetTcpBindingEndpointConfig" closeTimeout="00:15:00" openTimeout="00:15:00" sendTimeout="00:15:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <security mode="Transport" />
    </binding>
  </netTcpBinding>
</bindings>
<services>
  <service name="Level4Service.Service1">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBindingEndpointConfig" name="NetTcpBindingEndpoint" contract="Level4Service.IOrderService" />
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="mexTcpBidingEndpoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://Server1:1531/Design_Time_Addresses/Level4Service/Service1/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<add name="ERPContext" providerName="System.Data.SqlClient" connectionString="Data Source=Sqls1;Initial Catalog=ERP;User ID=sa_sysdev;Password=****" />
 </connectionStrings>
 <startup>
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
 </startup>
 <runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
   <dependentAssembly>
     <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.2.1.0" />
  </dependentAssembly>
 </assemblyBinding>
</runtime>
<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
 </providers>
</entityFramework>
</configuration>

问题出在哪里?

1 个答案:

答案 0 :(得分:0)

我在Service2enabled tracing,我在Service2致电Service1时发现以下错误。

  

该服务不允许您匿名登录。

所以使用this thread我找到了解决方案。

我的窗口Service1的帐户设置为LocalSystem,因此我将其更改为NetworkService并重新安装服务并解决了问题。