我有这种方法调用并尝试打开服务主机来侦听请求。它能够创建服务主机并启用元数据发布,但在尝试打开服务主机时失败。
当它到达host.Open()时无法打开服务主机,以便我从客户端发送消息。 为什么我的服务没有启动?
public void startOperator()
{
Uri baseAddress = new Uri("net.tcp://localhost/Test");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(Operator), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
// Open the ServiceHost to start listening for messages. Since
// no endpoints are explicitly configured, the runtime will create
// one endpoint per base address for each service contract implemented
// by the service.
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
任何帮助表示赞赏..谢谢
答案 0 :(得分:1)
请勿使用smb.HttpGetEnabled = true
选项,因为它与您的net.tcp
绑定冲突。在评论之后,代码对我有效。