2011-01-26 90 views
1

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

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

客户端配置为空:

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

在Web服务器上的配置是:

<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。 连接尝试持续时间为012:跨度为00:00:02.1041204。 TCP错误 代码10061:没有连接可能是因为目标机器 主动拒绝它127.0.0.1:808而产生的 。

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

我有一种感觉,有一件简单的事情,我失踪了。有人有主意吗?

回答

4

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

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

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

+0

谢谢,它被禁用,我启用并启动它。我也为Net Tcp Listener适配器做了同样的事情,但我仍然得到相同的错误 – 2011-01-26 14:22:52

+0

在IIS中托管时,该服务是否是一个因素?我不这么认为,但我可能是错的。 – Brook 2011-01-26 14:39:45