繁体   English   中英

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

[英]Calling a WCF service from another WCF service cause error

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

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

服务器堆栈跟踪:位于System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc&rpc)处,位于System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息答复,MessageFault错误,字符串操作,MessageVersion版本,FaultConverter faultConverter)。 ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔型单向,ProxyOperationRuntime操作,系统处的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)。 ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)

在[0]处抛出异常:在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)在IService1.GetHeatInstructionBy Service1Client.GetHeatInstructionByOrderItemId(Int32 orderItemId)上的Int32 orderItemId)

但把当Service2Server1 (2个服务, Server1 )没有错误的方法运行。

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>

问题出在哪儿?

我在Service2启用了跟踪 ,并且从Service1调用Service2发现以下错误。

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

因此,使用此线程,我找到了解决方案。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM