2011-01-06 147 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

相关问题