2011-01-06 149 views
0

我創建了一個WCF服務並通過控制檯託管它。但是當我創造了另一個Web應用程序,並試圖將其添加服務引用其給予錯誤通過控制檯託管WCF服務

元數據包含的引用 無法解析: 「的net.tcp://192.0.0.0:9100/ConsoleApplication3 /通訊.SVC/mextcp」。 無法連接到 net.tcp://192.0.0.0:9100/ConsoleApplication3/Communicator.svc/mextcp。 連接嘗試持續時間爲00:00:00.9843750,時間間隔爲 。 TCP 錯誤代碼10061:由於目標機器 主動拒絕192.0.0.0:9100,所以無法連接 。 由於目標機器主動拒絕 192.0.0.0:9100,因此無法建立連接。如果在當前解決方案中定義了該服務,請嘗試 構建解決方案並再次添加 服務參考。

這裏是代碼:

namespace ConsoleApplication3 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     try 
     { 
      using (ServiceHost host = new ServiceHost(typeof(Communicator))) 
      { 
       host.Open(); 
       Console.WriteLine("Press <Enter> to terminate the Host application."); 
       Console.ReadLine(); 
      } 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.Message); 
      Console.ReadLine(); 
     } 
    } 
} 

[ServiceContract] 
public interface ICommunicator 
{ 
    [OperationContract] 
    string SayHello(); 
} 

public class Communicator : ICommunicator 
{ 
    public string SayHello() 
    { 
     return "I am here"; 
    } 
} 

這裏是配置:

<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="ConsoleApplication3.Communicator" behaviorConfiguration="CommunicatorBehavior"> 
     <!-- Service Endpoints --> 
     <endpoint address="ConsoleApplication3" binding="netTcpBinding" 
      contract="ConsoleApplication3.ICommunicator"/> 
     <!-- This Endpoint is used for genertaing the proxy for the client --> 
     <!-- To avoid disclosing metadata information, set the value below to false and 
     remove the metadata endpoint above before deployment --> 
     <endpoint address="mex" contract="IMetadataExchange" binding="mexTcpBinding" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:9100/"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="CommunicatorBehavior"> 
      <serviceMetadata httpGetEnabled="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

回答

2

我覺得你有一個錯誤的地址,試圖爲您服務獲得。

您已經在控制檯應用程序中自行託管了一項服務,其中包含netTcpBinding,並且您已經定義了基地址net.tcp://localhost:9100/,MEx端點位於net.tcp://localhost:9100/mex

因此,您需要爲使用的基地址

net.tcp://localhost:9100/ 

或MEX地址

net.tcp://localhost:9100/mex 

試圖連接到該服務時。

我不知道你是怎麼想出你似乎試圖連接的這個地址(net.tcp://192.0.0.0:9100/ConsoleApplication3/Communicator.svc/mextcp) - 但這個地址是而不是有效。首先的 - 有當自託管一個netTcpBinding web服務中使用無* .svc文件,我不知道你在哪裏得到這個/mextcp地址.....

更新:我把你代碼,創建與接口和服務實現和服務配置一個新的控制檯應用程序,它工作得很好我的機器上:

alt text

我也得到了Windows防火牆的警告,當我試圖啓動在Visual Studio中關於允許訪問的控制檯應用程序 - 我確實允許。

+0

那麼應該是我試過的地址「的net.tcp://本地主機:9100/MEX 」,但還是一樣errror – BreakHead 2011-01-06 16:14:51

相關問題