zoukankan      html  css  js  c++  java
  • wcf超时错误

    错误信息(这个是从网上摘过来的)

    套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:01:00”

    原来是windows安全问题导致的,如果服务器端和客户端在同一个域环境里,没有这个问题 。我先是在局域网的两台机器测试的,服务器端是有加入域的,客户端是没有加入域的,

    开始客户端连都连不上通也不通,ping了一下,原来是杀毒软件的防火墙开着,后来关掉就OK了。公网服务器再试了一下,还是不行,原来是我没有设置好,把服务端的安全配置

    代码注释掉了。不多说了,看下面的代码设置

    <!--服务器端代码设置--> 
    <bindings>
          <netTcpBinding>
            <binding name="BindingBehaviorConfiguration">
    
              <security mode="None" >
    
                <transport clientCredentialType="None"></transport>
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
        <!--bindingConfiguration="BindingBehaviorConfiguration"-->
    
        <services>
          <service name="WCFColdChainService.UserService">
            <endpoint address="" binding="netTcpBinding" contract="IContracts.IUser" bindingConfiguration="BindingBehaviorConfiguration">
              <identity>
                <dns value="172.17.103.44" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://172.17.103.44:5600/WCFColdChainService/UserService/" />
              </baseAddresses>
            </host>
          </service>
    </services>
    //客户端我是用代码写的
      private static string strServer = ApplicationConfiguration.GetUrl("tcp");
            private static string strService = "/WCFColdChainService/UserService/";
    
            public static IUser GetUser()
            {
                //主要是这段的设置
                NetTcpBinding binding = new NetTcpBinding();
                binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
    //安全类型,客户端凭证设置成关闭
                binding.Security.Mode = SecurityMode.None;
                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                //此处添加地址
                EndpointAddress address = new EndpointAddress(strServer + strService);
    
                ChannelFactory<IUser> factory = new ChannelFactory<IUser>(binding
                    , address);
    
                IUser channel = factory.CreateChannel();
    
    
                return channel;
            }
    
    
            public static void CloseChannel(IUser icc)
            {
                ICommunicationObject channel = (ICommunicationObject)icc;
                channel.Close();
            }    

     

  • 相关阅读:
    Kafka设计解析(二)- Kafka High Availability (上)
    Kafka设计解析(三)- Kafka High Availability (下)
    Kafka深度解析
    Cloudera Manager(CDH5)内部结构、功能包括配置文件、目录位置等
    Failed to start /etc/rc.d/rc.local Compatibility
    Offset Management For Apache Kafka With Apache Spark Streaming
    maven-assembly-plugin打包可执行的jar包
    How Cigna Tuned Its Spark Streaming App for Real-time Processing with Apache Kafka
    SystemTap Beginners Guide
    数据可视化的开源方案: Superset vs Redash vs Metabase (二)
  • 原文地址:https://www.cnblogs.com/Anders888/p/3029715.html
Copyright © 2011-2022 走看看