Esempio n. 1
0
        private static void PingChannelFactoryTest()
        {
            string endpointConfigurationName = "BasicHttpBinding_IHelloService";

            BasicHttpBinding binding  = new BasicHttpBinding();
            EndpointAddress  endpoint = new EndpointAddress("http://localhost:8080/HelloService");

            //ChannelFactory<IHelloService> proxy = new ChannelFactory<IHelloService>(endpointConfigurationName);

            ChannelFactory <IHelloService> proxy = new ChannelFactory <IHelloService>(binding, endpoint);

            IHelloService client = proxy.CreateChannel();

            MessageHeader shareableInstanceContextHeader = MessageHeader.CreateHeader(
                "version",
                "http://domain.com",
                "1.0");

            using (var context = new OperationContextScope((IClientChannel)proxy))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(shareableInstanceContextHeader);
            }


            string result = client.Ping("Hello");

            Console.WriteLine(result);

            client.Send("World");
        }