首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF net.tcp通信错误

WCF net.tcp通信错误
EN

Stack Overflow用户
提问于 2012-05-18 22:00:44
回答 3查看 3K关注 0票数 0

我创建了一个带有net.tcp绑定的WCF服务,并且能够在我的控制台应用程序中添加对它的服务引用,而不会出现错误。

在这样做之后,我尝试在我的控制台应用程序中自我托管这个服务。服务主机被打开,但是当我使用服务引用对象调用服务中的方法时,我得到了这个异常

‘无法连接到net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/.。连接尝试持续的时间跨度为00:00:02.0800000。TCP错误代码10061:无法建立连接,因为目标计算机主动拒绝连接::1:808。’

这是我的cs文件代码

代码语言:javascript
复制
Main method()

 Service2Client sc2 = new Service2Client();
                Uri baseaddress = new Uri("net.tcp://localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2/");

                ServiceHost serviceHost = new ServiceHost(typeof(Service2Client), baseaddress);

                serviceHost.Open();

                Console.WriteLine(sc2.GetData(124)); --> exception comes at this point

                Console.ReadLine();

这是控制台应用中的app.config

代码语言:javascript
复制
<system.serviceModel>
    <client>
      <endpoint address="net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService2"
        contract="ServiceReference2.IService2" name="NetTcpBinding_IService2">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IService2" 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="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <!--<client>
      <endpoint address="net.tcp://localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2/"
        binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="MyWCFServiceLibrary.IService2"
        name="endpointClient" />
      <endpoint address="net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService2"
        contract="ServiceReference2.IService2" name="NetTcpBinding_IService2">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>-->
  </system.serviceModel>

环境: Vs2010

有人能在这方面帮我吗?

EN

回答 3

Stack Overflow用户

发布于 2012-05-18 22:08:04

这是可能的:

1) 防火墙正在拦截该请求。看看这个。

2)确保

  • Net.Tcp侦听器Adapter;
  • Net.Tcp端口共享Service

正在运行(Windows服务)

票数 2
EN

Stack Overflow用户

发布于 2012-05-18 22:53:00

您的客户端配置的URL为

net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/

鉴于您的服务处于打开状态

net.tcp://localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2/

控制台应用程序客户端终结点元素的app.config中缺少端口号。

票数 2
EN

Stack Overflow用户

发布于 2021-06-15 22:21:23

可能有多种原因,因为其他答案可以解决问题。但在我的案例中,问题在安装了挂起的windows更新后就解决了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10654071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档