【问题标题】:WCF 4 and NetTcpBindingWCF 4 和 NetTcpBinding
【发布时间】:2011-06-15 21:01:58
【问题描述】:

我正在测试 WCF 4 的无配置功能。

我已经构建了一个简单的服务并将其部署到 IIS。服务部署为 svc 文件

客户端配置为空:

<configuration>
    <system.serviceModel>
        <bindings />
        <client />
    </system.serviceModel>
</configuration>

网络服务器上的配置是:

<system.web>
   <compilation debug="true" targetFramework="4.0" />  
</system.web>   
<system.serviceModel>
   <behaviors>
      <serviceBehaviors>
         <behavior>
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
         </behavior>
      </serviceBehaviors>
   </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 
<system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

这段代码运行良好:

BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress("http://localhost/Service1.svc");
ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint);
IService1 wcfClient1 = myChannelFactory.CreateChannel();
int z = wcfClient1.Multiply(composite);

这段代码没有:

NetTcpBinding myBinding = new NetTcpBinding();
EndpointAddress myEndpoint = new EndpointAddress("net.tcp://localhost:808/Service1.svc");
ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint);
IService1 wcfClient1 = myChannelFactory.CreateChannel();
int z = wcfClient1.Multiply(composite);

我得到的错误是:

无法连接到 net.tcp://localhost/Service1.svc。这 连接尝试持续了一段时间 跨度为 00:00:02.1041204。 TCP 错误 代码 10061:无法连接 因为目标机器而制造 127.0.0.1:808 主动拒绝。

net.tcp 绑定是在默认网站上设置的。

我有一种感觉,我缺少一些简单的东西。有人有什么想法吗?

【问题讨论】:

    标签: c# wcf .net-4.0


    【解决方案1】:

    发现问题。虽然 net.tcp 看起来像是为默认网站安装的,但需要使用以下命令激活它:

     appcmd.exe set app "Default Web Site/" /enabledProtocols:http,net.tcp
    

    【讨论】:

    • 您也可以右键单击 IIS>默认网站,然后单击高级设置。您将看到最后一个选项“启用的协议”,您可以在那里添加 net.tcp。
    【解决方案2】:

    我感觉你的Net.Tcp端口共享服务没有启用。

    【讨论】:

    • 谢谢,它已被禁用,我启用并启动了它。我也为 Net Tcp Listener 适配器做了同样的事情,但我仍然得到同样的错误
    • 在 IIS 中托管时,该服务是否是一个因素?我不这么认为,但我可能是错的。
    • @Shiraz, @Brook - 不幸的是,我在这件事上的帮助有限,因为我从未在 IIS 中托管过 WCF TCP 服务。我在常规 Windows 服务中托管的问题似乎对您的问题的细节很熟悉。
    • 谢谢,帮我解决了这个问题,当服务器没有正确重启(reset)时,重启后服务可能不会自动启动。
    猜你喜欢
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    相关资源
    最近更新 更多