1,978
社区成员
发帖
与我相关
我的任务
分享
其实很简单,我们只需要在服务入口处添加Service的EndPoint即可。
Uri uri = new Uri(ConfigurationManager.AppSettings["addr"]);
using(ServiceHost host = new ServiceHost(typeof(NikeSoftChat.ChatService),uri))
{
ServiceMetadataBehavior smb = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
{
host.Description.Behaviors.Add(new ServiceMetadataBehavior());
}
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
host.Open();
Console.WriteLine("Chat service listen on endpoint {0}", uri.ToString());
Console.WriteLine("Press ENTER to stop chat service...");
Console.ReadLine();
host.Abort();
host.Close();
}
复制代码
注意,黄色标记很重要,它能够暴露出元数据出来,如果没有黄色标记部分,利用SvcUtil生成net.tcp的代理类和配置文件将是不可能的。