关于tcp通道下,启用httpget,必须启用一个http的基地址,如果要启用元数据交换,host中必须开启服务描述。

            //01 create host
            Uri tcpBaseAddress = new Uri("net.tcp://127.0.0.1:12345/kp");
            Uri httpBaseAddress = new Uri("http://127.0.0.1:12346/kp");
            ServiceHost host = new ServiceHost(typeof(Po), tcpBaseAddress, httpBaseAddress);

            //02 add service metadata behavior
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            host.Description.Behaviors.Add(smb);

            //03 add endpoint
            host.AddServiceEndpoint(typeof(IPo), new NetTcpBinding(), "PoSvc");
            host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); 
                
            host.Open();

            Console.ReadLine();

 

相关文章:

  • 2021-07-20
  • 2021-07-27
  • 2022-12-23
  • 2021-07-26
  • 2022-01-22
  • 2021-12-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2021-05-31
  • 2021-11-29
相关资源
相似解决方案