2012-05-18 84 views
0

我用net.tcp綁定創建了一個WCF服務,並且我能夠在控制檯應用程序中添加一個服務引用而沒有錯誤。WCF net.tcp通信錯誤

這樣做後,我試圖自己在我的控制檯應用程序中託管此服務。服務主機被打開,但是當我使用服務引用對象調用服務中的方法時,我得到此異常

'無法連接到net.tcp:// localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2 /。連接嘗試持續時間爲00:00:02.0800000。 TCP錯誤代碼10061:由於目標機器主動拒絕[:: 1]:808,因此無法建立連接。'

這是我的CS文件代碼

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

<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

任何一個可以請幫我在這。

+0

您的客戶端配置的URL爲net.tcp:// localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2 /,而您的服務位於net.tcp:// localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2 /上。港口號碼丟失 – Rajesh

回答

2

這是可能的:

1)防火牆阻塞該請求。一探究竟。

2)確保

  • 的net.tcp偵聽器適配器;
  • Net.Tcp端口共享服務

正在運行(Windows服務)

+0

嗨我認爲這可能不是問題,因爲該服務是本地的我的機器 – user1403505

+0

什麼操作系統,你開始你的應用程序? –

+0

我正在使用Windows 7 – user1403505

2

您的客戶端配置具有URL作爲

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

,而您的服務是

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

控制檯應用程序客戶端端點元素的app.config中缺少PORT編號。