WCF在tcp通道下启用httpget

关于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();

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。