public void BuildChannelFactoryForHttpEndpoint () { var b = new BasicHttpBinding (); b.Security.Mode = BasicHttpSecurityMode.Transport; var cf = b.BuildChannelFactory<IRequestChannel> (); cf.Open (); cf.CreateChannel (new EndpointAddress ("http://localhost:8080")); }
public static void Create_HttpBinding_SecurityMode_Without_SecurityBindingElement(BasicHttpSecurityMode securityMode) { BasicHttpBinding binding = new BasicHttpBinding(securityMode); var bindingElements = binding.CreateBindingElements(); var securityBindingElement = bindingElements.FirstOrDefault(x => x is SecurityBindingElement) as SecurityBindingElement; Assert.True(securityBindingElement == null, string.Format("securityBindingElement should be null when BasicHttpSecurityMode is '{0}'", securityMode)); Assert.True(binding.CanBuildChannelFactory<IRequestChannel>(), string.Format("CanBuildChannelFactory should return true for BasicHttpSecurityMode:'{0}'", securityMode)); binding.BuildChannelFactory<IRequestChannel>(); }
static void Main(string[] args) { Uri listenUri = new Uri("http://127.0.0.1:9999/listener"); Binding binding = new BasicHttpBinding(); IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>(); channelFactory.Open(); IRequestChannel channel = channelFactory.CreateChannel(new EndpointAddress(listenUri)); channel.Open(); Message replyMessage = channel.Request(CreateRequestMessage(binding)); Console.WriteLine("the reply message\n{0}", replyMessage); Console.Read(); }
static void Main(string[] args) { EndpointAddress address = new EndpointAddress("http://127.0.0.1:9999/messagingviabinding"); BasicHttpBinding binding = new BasicHttpBinding(); IChannelFactory<IRequestChannel> chananelFactory = binding.BuildChannelFactory<IRequestChannel>(); chananelFactory.Open(); IRequestChannel channel = chananelFactory.CreateChannel(address); channel.Open(); Message requestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://artech/messagingviabinding", "The is a request message manually created for the purpose of testing."); Message replyMessage = channel.Request(requestMessage); Console.WriteLine("Receive a reply message:\n{0}", replyMessage); channel.Close(); chananelFactory.Close(); Console.Read(); }
public static void IRequestChannel_Http_BasicHttpBinding() { IChannelFactory<IRequestChannel> factory = null; IRequestChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); // Create the channel factory factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); channel.Open(); // Create the Message object to send to the service. Message requestMessage = Message.CreateMessage( binding.MessageVersion, action, new CustomBodyWriter(clientMessage)); // *** EXECUTE *** \\ // Send the Message and receive the Response. replyMessage = channel.Request(requestMessage); // *** VALIDATE *** \\ // BasicHttpBinding uses SOAP1.1 which doesn't return the Headers.Action property in the Response // Therefore not validating this property as we do in the test "InvokeIRequestChannelCreatedViaBinding" var replyReader = replyMessage.GetReaderAtBodyContents(); string actualResponse = replyReader.ReadElementContentAsString(); string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; Assert.Equal(expectedResponse, actualResponse); // *** CLEANUP *** \\ replyMessage.Close(); channel.Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }
public static void IRequestChannel_Http_BasicHttpBinding() { try { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); // Create the channel factory IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>( new BindingParameterCollection()); factory.Open(); // Create the channel. IRequestChannel channel = factory.CreateChannel( new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); channel.Open(); // Create the Message object to send to the service. Message requestMessage = Message.CreateMessage( binding.MessageVersion, action, new CustomBodyWriter(clientMessage)); // Send the Message and receive the Response. Message replyMessage = channel.Request(requestMessage); // BasicHttpBinding uses SOAP1.1 which doesn't return the Headers.Action property in the Response // Therefore not validating this property as we do in the test "InvokeIRequestChannelCreatedViaBinding" var replyReader = replyMessage.GetReaderAtBodyContents(); string actualResponse = replyReader.ReadElementContentAsString(); string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; if (!string.Equals(actualResponse, expectedResponse)) { Assert.True(false, String.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse)); } replyMessage.Close(); channel.Close(); factory.Close(); } catch (Exception ex) { Assert.True(false, String.Format("Unexpected exception was caught: {0}", ex.ToString())); } }
static void Main(string[] args) { Uri listenUri = new Uri("http://127.0.0.1:3721/listener"); Binding binding = new BasicHttpBinding(); //创建、开启信道工厂 IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>(); channelFactory.Open(); //创建、开启请求信道 IRequestChannel channel = channelFactory.CreateChannel(new EndpointAddress(listenUri)); channel.Open(); //发送请求消息,接收回复消息 Message replyMessage = channel.Request(CreateRequestMessage(binding)); Console.WriteLine(replyMessage); Console.Read(); }
static void Main(string[] args) { EndpointAddress address = new EndpointAddress("http://localhost:1111/MessageViaBinding"); var binding = new BasicHttpBinding(); var channelFactory = binding.BuildChannelFactory<IRequestChannel>(); channelFactory.Open(); var channel = channelFactory.CreateChannel(address); channel.Open(); var message = Message.CreateMessage(MessageVersion.Soap11, "http://MessageViaBinding", "The is a request message manually created for the purpose of testing."); Message replayMessage=channel.Request(message); Console.WriteLine("Receive a reply message:\n{0}", replayMessage); channel.Close(); channelFactory.Close(); Console.ReadLine(); }
public static void Main () { Binding b = new BasicHttpBinding (); IChannelFactory<IRequestChannel> cf = b.BuildChannelFactory<IRequestChannel> ( new BindingParameterCollection ()); cf.Open (); IRequestChannel req = cf.CreateChannel ( new EndpointAddress ("http://localhost:8080/")); Console.WriteLine (req.State); req.Open (); Message msg = Message.CreateMessage (MessageVersion.Soap11, "http://tempuri.org/IFoo/ProcessMessage", new EchoType ("hoge")); Message ret = req.Request (msg); Console.WriteLine (req.State); var p = ret.Properties [HttpResponseMessageProperty.Name] as HttpResponseMessageProperty; Console.WriteLine (p.StatusCode); using (XmlWriter w = XmlWriter.Create (Console.Out)) { ret.WriteMessage (w); } }
public static void Main () { Binding b = new BasicHttpBinding (); IChannelFactory<IRequestChannel> cf = b.BuildChannelFactory<IRequestChannel> ( new BindingParameterCollection ()); cf.Open (); IRequestChannel req = cf.CreateChannel ( new EndpointAddress ("http://localhost:8080/")); Console.WriteLine (req.State); req.Open (); Message msg = Message.CreateMessage (MessageVersion.Soap11, "http://tempuri.org/IFoo/Echo", new EchoType ("hoge")); //Message ret = req.Request (msg); IAsyncResult result = req.BeginRequest (msg, null, null); //return; Message ret = req.EndRequest (result); Console.WriteLine (req.State); using (XmlWriter w = XmlWriter.Create (Console.Out)) { ret.WriteMessage (w); } }
public static void Custom_Message_RoundTrips() { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); // Create the channel factory IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. IRequestChannel channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); channel.Open(); // Create the Message object to send to the service. using (Message requestMessage = Message.CreateMessage( binding.MessageVersion, action, new CustomBodyWriter(clientMessage))) { // Send the Message and receive the Response. using (Message replyMessage = channel.Request(requestMessage)) { Assert.False(replyMessage.IsFault); Assert.False(replyMessage.IsEmpty); Assert.Equal(MessageState.Created, replyMessage.State); Assert.Equal(MessageVersion.Soap11, replyMessage.Version); var replyReader = replyMessage.GetReaderAtBodyContents(); string actualResponse = replyReader.ReadElementContentAsString(); string expectedResponse = "Test Custom_Message_RoundTrips.[service] Request received, this is my Reply."; Assert.True(string.Equals(actualResponse, expectedResponse), string.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse)); } } channel.Close(); factory.Close(); }
public static void Main () { var b = new BasicHttpBinding (); b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; var cc = new ClientCredentials (); cc.UserName.UserName = "******"; IChannelFactory<IRequestChannel> cf = b.BuildChannelFactory<IRequestChannel> (cc); cf.Open (); IRequestChannel req = cf.CreateChannel ( new EndpointAddress ("http://localhost:8080/")); Console.WriteLine (cf.GetProperty<ClientCredentials> ()); req.Open (); Message msg = Message.CreateMessage (MessageVersion.Soap11, "http://tempuri.org/IFoo/Echo", new EchoType ("hoge")); //Message ret = req.Request (msg); IAsyncResult result = req.BeginRequest (msg, null, null); //return; Message ret = req.EndRequest (result); using (XmlWriter w = XmlWriter.Create (Console.Out)) { ret.WriteMessage (w); } }
public static void IDuplexSessionChannel_Http_BasicHttpBinding() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); if (!root_Certificate_Installed) { Console.WriteLine("---- Test SKIPPED --------------"); Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE."); Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed); return; } #endif IChannelFactory<IDuplexSessionChannel> factory = null; IDuplexSessionChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ BasicHttpBinding binding = new BasicHttpBinding(); // Create the channel factory factory = binding.BuildChannelFactory<IDuplexSessionChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps)); channel.Open(); // Create the Message object to send to the service. Message requestMessage = Message.CreateMessage( binding.MessageVersion, action, new CustomBodyWriter(clientMessage)); requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid()); // *** EXECUTE *** \\ // Send the Message and receive the Response. channel.Send(requestMessage); replyMessage = channel.Receive(TimeSpan.FromSeconds(5)); // *** VALIDATE *** \\ // If the incoming Message did not contain the same UniqueId used for the MessageId of the outgoing Message we would have received a Fault from the Service Assert.Equal(requestMessage.Headers.MessageId.ToString(), replyMessage.Headers.RelatesTo.ToString()); // Validate the Response var replyReader = replyMessage.GetReaderAtBodyContents(); string actualResponse = replyReader.ReadElementContentAsString(); string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; Assert.Equal(expectedResponse, actualResponse); // *** CLEANUP *** \\ replyMessage.Close(); channel.Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }
static WcfRoutingService() { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); _factory = binding.BuildChannelFactory<IRequestChannel>(); _factory.Open(); }