繁体   English   中英

IIS问题上的WCF net.tcp服务

[英]WCF net.tcp service on IIS issue

我正在做一个客户端-服务器项目,其中客户端通过Internet部署。 所有服务均使用WCF编写并使用wsHttpBinding 我需要实现客户端回调功能,并且由于客户端位于防火墙和NAT之后,因此我被告知可以使用绕过防火墙/ NAT的netTcpBinding 因此,我创建了服务和回调合同。

在客户端,这就是我尝试连接到它的方式:

var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;

AuthorizationToken authorizationToken = 
  new AuthorizationToken(Session.Current.Username, Session.Current.Password, RequiredPermission.User);

using (DuplexChannelFactory<INotificationService> channel =
       new DuplexChannelFactory<INotificationService>(new InstanceContext(this), binding,
       new EndpointAddress("net.tcp://mywebsite.com:808/MyServices/NotificationService.svc")))
{
    channel.Credentials.UserName.UserName = authorizationToken.FormatTokenForTransmission();

    channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = 
       System.ServiceModel.Security.X509CertificateValidationMode.None;

    INotificationService proxy = channel.CreateChannel();
    proxy.Subscribe();
}

除了绑定类型和ChannelFactory之外,该代码与连接到wsHttpBinding服务的代码几乎相同。 web.config也看起来像这样:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpConfig" maxReceivedMessageSize="2147483647">
          <security mode="Message" >
            <message clientCredentialType="UserName"/>
          </security>
          <readerQuotas maxArrayLength="2147483647"/>
        </binding>
      </wsHttpBinding>
      <netTcpBinding>
        <binding name="netTcpConfig">
             <security mode="Message" >
                <message clientCredentialType="UserName"/>
             </security>
             <readerQuotas maxArrayLength="2147483647"/>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service name="MyProject.Services.NotificationService" behaviorConfiguration="authenticationBehavior">
        <endpoint binding="netTcpBinding" bindingConfiguration="netTcpConfig" 
          contract="MyProject.ServiceContracts.INotificationService" />

        <endpoint address="mex" 
                  binding="mexTcpBinding" 
                  bindingConfiguration=""
                  name="MyServiceMexTcpBidingEndpoint" 
                  contract="IMetadataExchange" />

      </service>

      // other non-net.tcp services go here
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="authenticationBehavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceCredentials>
            <serviceCertificate findValue="SomeCertificate" storeLocation="LocalMachine"
              storeName="TrustedPeople" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom"
              customUserNamePasswordValidatorType="MyProject.Authentication.CustomAuthenticator, MyProject.Authentication" />
          </serviceCredentials>
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

当我进行服务调用时,请求确实到达了IIS ,但是抛出了一个异常而没有内部异常消息,并且在服务器端,我得到了以下跟踪日志:

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 '00:01:00

我知道这是一个非常普遍的错误,我的问题是,您是否发现我的Web配置设置有问题? 任何帮助表示赞赏。

可能有多种原因-

1)检查您的net.tcp适配器服务是否正在运行(甚至尝试将其重置一次)2)检查您的IIS服务是否配置为通过Tcp绑定3)检查tcp端口是否打开4)最后尝试增加超时时间

暂无
暂无

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

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