我创建了一个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>
那么应该是我试过的地址“的net.tcp://本地主机:9100/MEX ”,但还是一样errror – BreakHead 2011-01-06 16:14:51