public static void Main () { HttpTransportBindingElement el = new HttpTransportBindingElement (); IChannelFactory<IRequestChannel> factory = el.BuildChannelFactory<IRequestChannel> ( new BindingContext (new CustomBinding (), new BindingParameterCollection ())); factory.Open (); IRequestChannel request = factory.CreateChannel ( new EndpointAddress ("http://localhost:37564")); request.Open (); using (XmlWriter w = XmlWriter.Create (Console.Out)) { Message.CreateMessage (MessageVersion.Default, "Echo") .WriteMessage (w); } Console.WriteLine (); Message msg = request.Request ( Message.CreateMessage (MessageVersion.Default, "Echo"), TimeSpan.FromSeconds (15)); using (XmlWriter w = XmlWriter.Create (Console.Out)) { msg.WriteMessage (w); } }
public static void Main() { HttpTransportBindingElement el = new HttpTransportBindingElement(); IChannelFactory <IRequestChannel> factory = el.BuildChannelFactory <IRequestChannel> ( new BindingContext(new CustomBinding(), new BindingParameterCollection())); factory.Open(); IRequestChannel request = factory.CreateChannel( new EndpointAddress("http://localhost:37564")); request.Open(); using (XmlWriter w = XmlWriter.Create(Console.Out)) { Message.CreateMessage(MessageVersion.Default, "Echo") .WriteMessage(w); } Console.WriteLine(); Message msg = request.Request( Message.CreateMessage(MessageVersion.Default, "Echo"), TimeSpan.FromSeconds(15)); using (XmlWriter w = XmlWriter.Create(Console.Out)) { msg.WriteMessage(w); } }
public static ChannelManagerBase GetChannelManagerBase() { HttpTransportBindingElement httpBE = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(httpBE); return((ChannelManagerBase)httpBE.BuildChannelFactory <IRequestChannel>(new BindingContext(binding, new BindingParameterCollection()))); }
// Now this test is mostly useless ... public void ConsumeBindingElements() { BindingContext ctx = new BindingContext( new CustomBinding( new TextMessageEncodingBindingElement(), new HttpTransportBindingElement()), new BindingParameterCollection()); HttpTransportBindingElement be = new HttpTransportBindingElement(); be.BuildChannelFactory <IRequestChannel> (ctx); }
public static void Main() { HttpTransportBindingElement el = new HttpTransportBindingElement(); IChannelListener <IReplyChannel> listener = el.BuildChannelListener <IReplyChannel> ( new BindingContext(new CustomBinding(), new BindingParameterCollection(), new Uri("http://localhost:37564"), String.Empty, ListenUriMode.Explicit)); IChannelFactory <IRequestChannel> factory = el.BuildChannelFactory <IRequestChannel> ( new BindingContext(new CustomBinding(), new BindingParameterCollection())); listener.Open(); factory.Open(); IRequestChannel request = factory.CreateChannel( new EndpointAddress("http://localhost:37564")); IReplyChannel reply = listener.AcceptChannel(); reply.Open(); request.Open(); new Thread(delegate() { try { RunListener(reply); } catch (Exception ex) { Console.WriteLine(ex); } }).Start(); Message msg = request.Request(Message.CreateMessage( MessageVersion.Default, "Echo"), TimeSpan.FromSeconds(15)); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; StringWriter sw = new StringWriter(); using (XmlWriter w = XmlWriter.Create(sw, settings)) { msg.WriteMessage(w); } Console.WriteLine(sw); }
public static void Snippet16() { // <Snippet16> CustomBinding binding = new CustomBinding(); HttpTransportBindingElement element = new HttpTransportBindingElement(); BindingParameterCollection parameters = new BindingParameterCollection(); BindingContext context = new BindingContext(binding, parameters); IChannelFactory <IRequestChannel> factory = element.BuildChannelFactory <IRequestChannel>(context); factory.Open(); EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp"); IRequestChannel channel = factory.CreateChannel(address); channel.Open(); Message request = Message.CreateMessage(MessageVersion.Default, "hello"); Message reply = channel.Request(request); Console.Out.WriteLine(reply.Headers.Action); reply.Close(); channel.Close(); factory.Close(); // </Snippet16> }
public static void Main () { HttpTransportBindingElement el = new HttpTransportBindingElement (); IChannelListener<IReplyChannel> listener = el.BuildChannelListener<IReplyChannel> ( new BindingContext (new CustomBinding (), new BindingParameterCollection (), new Uri ("http://localhost:37564"), String.Empty, ListenUriMode.Explicit)); IChannelFactory<IRequestChannel> factory = el.BuildChannelFactory<IRequestChannel> ( new BindingContext (new CustomBinding (), new BindingParameterCollection ())); listener.Open (); factory.Open (); IRequestChannel request = factory.CreateChannel ( new EndpointAddress ("http://localhost:37564")); IReplyChannel reply = listener.AcceptChannel (); reply.Open (); request.Open (); new Thread (delegate () { try { RunListener (reply); } catch (Exception ex) { Console.WriteLine (ex); } }).Start (); Message msg = request.Request (Message.CreateMessage ( MessageVersion.Default, "Echo"), TimeSpan.FromSeconds (15)); XmlWriterSettings settings = new XmlWriterSettings (); settings.OmitXmlDeclaration = true; StringWriter sw = new StringWriter (); using (XmlWriter w = XmlWriter.Create (sw, settings)) { msg.WriteMessage (w); } Console.WriteLine (sw); }
// It is almost identical to http-low-level-binding public void LowLevelHttpConnection () { HttpTransportBindingElement lel = new HttpTransportBindingElement (); // Service BindingContext lbc = new BindingContext ( new CustomBinding (), new BindingParameterCollection (), new Uri ("http://localhost:37564"), String.Empty, ListenUriMode.Explicit); listener = lel.BuildChannelListener<IReplyChannel> (lbc); try { listener.Open (); svcret = ""; Thread svc = new Thread (delegate () { try { svcret = LowLevelHttpConnection_SetupService (); } catch (Exception ex) { svcret = ex.ToString (); } }); svc.Start (); // Client code goes here. HttpTransportBindingElement el = new HttpTransportBindingElement (); BindingContext ctx = new BindingContext ( new CustomBinding (), new BindingParameterCollection ()); IChannelFactory<IRequestChannel> factory = el.BuildChannelFactory<IRequestChannel> (ctx); factory.Open (); IRequestChannel request = factory.CreateChannel ( new EndpointAddress ("http://localhost:37564")); request.Open (); try { try { Message reqmsg = Message.CreateMessage ( MessageVersion.Default, "Echo"); // sync version does not work here. Message msg = request.Request (reqmsg, TimeSpan.FromSeconds (5)); using (XmlWriter w = XmlWriter.Create (TextWriter.Null)) { msg.WriteMessage (w); } if (svcret != null) Assert.Fail (svcret.Length > 0 ? svcret : "service code did not finish until this test expected."); } finally { if (request.State == CommunicationState.Opened) request.Close (); } } finally { if (factory.State == CommunicationState.Opened) factory.Close (); } } finally { if (listener.State == CommunicationState.Opened) listener.Close (); } }
// It is almost identical to http-low-level-binding public void LowLevelHttpConnection() { HttpTransportBindingElement lel = new HttpTransportBindingElement(); // Service BindingContext lbc = new BindingContext( new CustomBinding(), new BindingParameterCollection(), new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), String.Empty, ListenUriMode.Explicit); listener = lel.BuildChannelListener <IReplyChannel> (lbc); try { listener.Open(); svcret = ""; Thread svc = new Thread(delegate() { try { svcret = LowLevelHttpConnection_SetupService(); } catch (Exception ex) { svcret = ex.ToString(); } }); svc.Start(); // Client code goes here. HttpTransportBindingElement el = new HttpTransportBindingElement(); BindingContext ctx = new BindingContext( new CustomBinding(), new BindingParameterCollection()); IChannelFactory <IRequestChannel> factory = el.BuildChannelFactory <IRequestChannel> (ctx); factory.Open(); IRequestChannel request = factory.CreateChannel( new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort())); request.Open(); try { try { Message reqmsg = Message.CreateMessage( MessageVersion.Default, "Echo"); // sync version does not work here. Message msg = request.Request(reqmsg, TimeSpan.FromSeconds(5)); using (XmlWriter w = XmlWriter.Create(TextWriter.Null)) { msg.WriteMessage(w); } if (svcret != null) { Assert.Fail(svcret.Length > 0 ? svcret : "service code did not finish until this test expected."); } } finally { if (request.State == CommunicationState.Opened) { request.Close(); } } } finally { if (factory.State == CommunicationState.Opened) { factory.Close(); } } } finally { if (listener.State == CommunicationState.Opened) { listener.Close(); } } }
public static ChannelManagerBase GetChannelManagerBase() { HttpTransportBindingElement httpBE = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(httpBE); return (ChannelManagerBase)httpBE.BuildChannelFactory<IRequestChannel>(new BindingContext(binding, new BindingParameterCollection())); }
// Now this test is mostly useless ... public void ConsumeBindingElements () { BindingContext ctx = new BindingContext ( new CustomBinding ( new TextMessageEncodingBindingElement (), new HttpTransportBindingElement ()), new BindingParameterCollection ()); HttpTransportBindingElement be = new HttpTransportBindingElement (); be.BuildChannelFactory<IRequestChannel> (ctx); }