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();
            }    

     

  • 相关阅读:
    Creating a Simple Direct2D Application
    关于ssh加密方式的理解
    关于2147217913 从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界 的问题解决方法
    关于 win2003中ASP.Net 的edit configuration 无法使用的答疑
    vc 用ado访问Oracle数据库的代码示例
    手工移除vs6的VSS绑定
    关于:无法执行值从 char 到 char 的隐性转换,因为该值的排序规则因排序规则冲突而未能解决
    vs2003 无法进行调试的经历
    关于如何在VMware上安装Puppy Linux
    VB: DataGrid 的列可见问题
  • 原文地址:https://www.cnblogs.com/Anders888/p/3029715.html
Copyright © 2011-2022 走看看