VictorStone

导航

 

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

 

posted on 2015-02-10 10:45  VictorStone  阅读(286)  评论(0编辑  收藏  举报