【发布时间】:2011-01-06 16:05:09
【问题描述】:
我创建了一个 WCF 服务并通过控制台托管它。但是当我创建另一个 Web 应用程序并尝试添加它的服务引用时,它给出了错误
元数据包含一个引用 无法解决: 'net.tcp://192.0.0.0:9100/ConsoleApplication3/Communicator.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>
【问题讨论】: