2011-01-26 151 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