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

 

你可能感兴趣的:(http)