internal protected override async Task OnCloseAsync(TimeSpan timeout) { if (_innerFactory != null) { IAsyncChannelFactory asyncFactory = _innerFactory as IAsyncChannelFactory; if (asyncFactory != null) { await asyncFactory.CloseAsync(timeout); } else { _innerFactory.Close(timeout); } } }
//入口方法 static void Main(string[] args) { try { //建立自定义的通道栈 BindingElement[] bindingElements = new BindingElement[3]; bindingElements[0] = new TextMessageEncodingBindingElement(); //OneWayBindingElement可以使得传输通道支持数据报模式 bindingElements[1] = new OneWayBindingElement(); bindingElements[2] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body")) { //创建ChannelFactory IChannelFactory <IOutputChannel> factory = binding.BuildChannelFactory <IOutputChannel>(new BindingParameterCollection()); factory.Open(); //这里创建IOutputChannel IOutputChannel outputChannel = factory.CreateChannel(new EndpointAddress("http://localhost/InputService")); outputChannel.Open(); //发送消息 outputChannel.Send(message); Console.WriteLine("已经成功发送消息!"); outputChannel.Close(); factory.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.Read(); } }
protected override void OnClose(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); base.OnClose(timeoutHelper.RemainingTime()); _innerChannelFactory.Close(timeoutHelper.RemainingTime()); }
static void Main(string[] args) { try { //使用说明先启动input,然后在启动启动output。 //记得使用管理员启动VS,我在程序清单中添加了管理员权限。 //创建自定义通道 BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); //文本编码 bindingElements[1] = new HttpTransportBindingElement(); //Htp传输 CustomBinding binding = new CustomBinding(bindingElements); using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body")) { //创建ChannelFactory request 请求 reply回复 IChannelFactory <IRequestChannel> factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection()); factory.Open(); //打开ChannelFactory //这里创建IRequestChannel IRequestChannel requestChannel = factory.CreateChannel(new System.ServiceModel.EndpointAddress("http://localhost:9090/RequestReplyService")); requestChannel.Open(); //打开通道 Message response = requestChannel.Request(message); //发送消息 Console.WriteLine("已经成功发送消息!"); //查看返回消息 Console.WriteLine($"接收到一条返回消息,action为:{response.Headers.Action},body为{response.GetBody<String>()}"); requestChannel.Close(); //关闭通道 factory.Close(); //关闭工厂 } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.Read(); } }
protected override void OnClose(TimeSpan timeout) { if (_innerFactory != null) { _innerFactory.Close(timeout); } }
public static void Snippet3() { // <Snippet3> CustomBinding binding = new CustomBinding(); binding.Elements.Add(new HttpTransportBindingElement()); Object[] bindingParams = new Object[2]; // <Snippet30> IChannelFactory <IRequestChannel> factory = binding.BuildChannelFactory <IRequestChannel>(bindingParams); factory.Open(); EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp"); IRequestChannel channel = factory.CreateChannel(address); channel.Open(); // </Snippet30> Message request = Message.CreateMessage(MessageVersion.Default, "hello"); Message reply = channel.Request(request); Console.Out.WriteLine(reply.Headers.Action); reply.Close(); channel.Close(); factory.Close(); // </Snippet3> }
//入口方法 static void Main(string[] args) { try { NetTcpBinding binding = new NetTcpBinding(); using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body")) { //创建ChannelFactory IChannelFactory <IDuplexChannel> factory = binding.BuildChannelFactory <IDuplexChannel>(new BindingParameterCollection()); factory.Open(); //这里创建IRequestChannel IDuplexChannel duplexChannel = factory.CreateChannel(new EndpointAddress("net.tcp://localhost:9090/DuplexService/Point2")); duplexChannel.Open(); //发送消息 duplexChannel.Send(message); Console.WriteLine("已经成功发送消息!"); //var msg = duplexChannel.Receive(); //Console.WriteLine($"收到消息:{msg.GetBody<string>()}"); duplexChannel.Close(); factory.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.Read(); } }
public void CheckDuplicateAuthenticatorTypesClient() { SymmetricSecurityBindingElement be = new SymmetricSecurityBindingElement(); be.ProtectionTokenParameters = new X509SecurityTokenParameters(); be.EndpointSupportingTokenParameters.Endorsing.Add( new X509SecurityTokenParameters()); // This causes multiple supporting token authenticator // of the same type. be.OptionalEndpointSupportingTokenParameters.Endorsing.Add( new X509SecurityTokenParameters()); Binding b = new CustomBinding(be, new HttpTransportBindingElement()); ClientCredentials cred = new ClientCredentials(); cred.ClientCertificate.Certificate = new X509Certificate2(TestResourceHelper.GetFullPathOfResource("Test/Resources/test.pfx"), "mono"); IChannelFactory <IReplyChannel> ch = b.BuildChannelFactory <IReplyChannel> (new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), cred); try { ch.Open(); } finally { if (ch.State == CommunicationState.Closed) { ch.Close(); } } }
public override void Dispose() { if (_channelFactory != null) { _channelFactory.Close(); } }
void RunTest() { listener.Open(); Thread thread = new Thread(ServerThread); thread.Start(this); CustomBinding binding = new CustomBinding(new WseTcpTransportBindingElement()); IChannelFactory <IDuplexSessionChannel> channelFactory = binding.BuildChannelFactory <IDuplexSessionChannel>(); channelFactory.Open(); IDuplexSessionChannel channel = channelFactory.CreateChannel(new EndpointAddress(this.uri)); Message requestMessage; channel.Open(); requestMessage = Message.CreateMessage(binding.MessageVersion, "http://SayHello", "to you."); channel.Send(requestMessage); Message hello = channel.Receive(); using (hello) { Console.WriteLine(hello.GetBody <string>()); } Console.WriteLine("Press enter."); Console.ReadLine(); requestMessage = Message.CreateMessage(binding.MessageVersion, "http://NotHello", "to me."); channel.Send(requestMessage); channel.Close(); thread.Join(); channelFactory.Close(); listener.Close(); Console.WriteLine("Press enter."); Console.ReadLine(); }
[Issue(1398, OS = OSID.AnyOSX)] // Cert installation on OSX does not work yet public static void IRequestChannel_Https_NetHttpsBinding() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); bool ssl_Available = SSL_Available(); if (!root_Certificate_Installed || !ssl_Available) { 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); Console.WriteLine("SSL_Available evaluated as {0}", ssl_Available); return; } #endif IChannelFactory <IRequestChannel> factory = null; IRequestChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport); // Create the channel factory factory = binding.BuildChannelFactory <IRequestChannel>(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)); // *** EXECUTE *** \\ // Send the Message and receive the Response. replyMessage = channel.Request(requestMessage); // *** VALIDATE *** \\ 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); } }
private static NetworkDetector.ConnectivityStatus CheckTcpConnectivity(Uri baseAddress, out Exception exception) { NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable; exception = null; if (!RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTP", false) && !RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTPS", false)) { try { BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); TcpTransportBindingElement tcpTransportBindingElement = new TcpTransportBindingElement(); tcpTransportBindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 100; tcpTransportBindingElement.MaxReceivedMessageSize = (long)65536; CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(binaryMessageEncodingBindingElement); customBinding.Elements.Add(tcpTransportBindingElement); customBinding.OpenTimeout = TimeSpan.FromSeconds(10); customBinding.SendTimeout = TimeSpan.FromSeconds(10); customBinding.ReceiveTimeout = TimeSpan.MaxValue; int num = 9350; Uri uri = ServiceBusUriHelper.CreateServiceUri("net.tcp", string.Concat(baseAddress.DnsSafeHost, ":", num.ToString(CultureInfo.InvariantCulture)), "/"); IChannelFactory <IDuplexSessionChannel> channelFactory = null; IDuplexSessionChannel duplexSessionChannel = null; try { channelFactory = customBinding.BuildChannelFactory <IDuplexSessionChannel>(new object[0]); channelFactory.Open(); duplexSessionChannel = channelFactory.CreateChannel(new EndpointAddress(uri, new AddressHeader[0])); duplexSessionChannel.Open(); Message message = Message.CreateMessage(MessageVersion.Default, "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/OnewayPing", new OnewayPingMessage()); duplexSessionChannel.Send(message, customBinding.SendTimeout); duplexSessionChannel.Close(); duplexSessionChannel = null; channelFactory.Close(); channelFactory = null; } finally { if (duplexSessionChannel != null) { duplexSessionChannel.Abort(); } if (channelFactory != null) { channelFactory.Abort(); } } connectivityStatu = NetworkDetector.ConnectivityStatus.Available; } catch (CommunicationException communicationException) { exception = communicationException; } catch (TimeoutException timeoutException) { exception = timeoutException; } } NetworkDetector.LogResult(baseAddress, "Tcp", connectivityStatu); return(connectivityStatu); }
//入口方法 static void Main(string[] args) { try { //建立自定义的通道栈 BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body")) { //创建ChannelFactory IChannelFactory <IRequestChannel> factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection()); factory.Open(); //这里创建IRequestChannel IRequestChannel requestChannel = factory.CreateChannel(new EndpointAddress("http://localhost/RequestReplyService")); requestChannel.Open(); //发送消息 Message response = requestChannel.Request(message); Console.WriteLine("已经成功发送消息!"); //查看返回消息 Console.WriteLine("接受到一条返回消息,action为:{0},body为:{1}", response.Headers.Action, response.GetBody <String>()); requestChannel.Close(); factory.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.Read(); } }
public static void IDuplexSessionChannel_Tcp_NetTcpBinding() { StringBuilder errorBuilder = new StringBuilder(); try { NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); // Create the channel factory IChannelFactory <IDuplexSessionChannel> factory = binding.BuildChannelFactory <IDuplexSessionChannel>( new BindingParameterCollection()); factory.Open(); // Create the channel. IDuplexSessionChannel channel = factory.CreateChannel( new EndpointAddress(Endpoints.Tcp_NoSecurity_Address)); 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()); // Send the Message and receive the Response. channel.Send(requestMessage); Message replyMessage = channel.Receive(TimeSpan.FromSeconds(5)); // 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 if (!String.Equals(replyMessage.Headers.RelatesTo.ToString(), requestMessage.Headers.MessageId.ToString())) { errorBuilder.AppendLine(String.Format("The MessageId of the incoming Message does not match the MessageId of the outgoing Message, expected: {0} but got: {1}", requestMessage.Headers.MessageId, replyMessage.Headers.RelatesTo)); } // 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."; if (!string.Equals(actualResponse, expectedResponse)) { errorBuilder.AppendLine(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) { errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString())); } Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: CustomBindingTest FAILED with the following errors: {0}", errorBuilder)); }
private void CloseChannelFactory(IChannelFactory channelFactory) { if (channelFactory == null) { return; } channelFactory.Close(); channelFactory.Abort(); }
public static void IDuplexSessionChannel_Https_NetHttpsBinding() { IChannelFactory <IDuplexSessionChannel> factory = null; IDuplexSessionChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport); // Create the channel factory factory = binding.BuildChannelFactory <IDuplexSessionChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttpsWebSockets)); 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 string expectedMessageID = requestMessage.Headers.MessageId.ToString(); string actualMessageID = replyMessage.Headers.RelatesTo.ToString(); Assert.True(String.Equals(expectedMessageID, actualMessageID), String.Format("Expected Message ID was {0}. Actual was {1}", expectedMessageID, actualMessageID)); // 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.Session.CloseOutputSession(); channel.Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }
public void Dispose() { if (_contactService != null) { IChannelFactory channel = _contactService as IChannelFactory; if (channel != null && channel.State != CommunicationState.Closed) { channel.Close(); } } }
public static void IRequestChannel_Http_CustomBinding() { try { BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); // Create the channel factory for the request-reply message exchange pattern. IChannelFactory <IRequestChannel> factory = binding.BuildChannelFactory <IRequestChannel>( new BindingParameterCollection()); factory.Open(); // Create the channel. IRequestChannel channel = factory.CreateChannel( new EndpointAddress(BaseAddress.HttpBaseAddress)); 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); string replyMessageAction = replyMessage.Headers.Action; if (!string.Equals(replyMessageAction, action + "Response")) { Assert.True(false, String.Format("A response was received from the Service but it was not the expected Action, expected: {0} actual: {1}", action + "Response", replyMessageAction)); } 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())); } }
public static void Desconectar() { if (_servicoLocalizador != null) { _servicoLocalizador = null; } if (_canal != null) { _canal.Close(); } }
//Closing the channelFactory - this also closes all the channels created by this channelFactory private void CleanupClient() { Log.Trace("Clients Cleanup ..."); foreach (ServiceContract serviceContract in Parameters.ServiceContracts) { switch (serviceContract) { case ServiceContract.IAsyncOneWay: asyncOneWayChannelFactory.Close(); break; case ServiceContract.IAsyncSessionOneWay: asyncSessionOneWayChannelFactory.Close(); break; case ServiceContract.IAsyncTwoWay: asyncTwoWayChannelFactory.Close(); break; case ServiceContract.IAsyncSessionTwoWay: asyncSessionTwoWayChannelFactory.Close(); break; case ServiceContract.ISyncOneWay: syncOneWayChannelFactory.Close(); break; case ServiceContract.ISyncSessionOneWay: syncSessionOneWayChannelFactory.Close(); break; case ServiceContract.ISyncTwoWay: syncTwoWayChannelFactory.Close(); break; case ServiceContract.ISyncSessionTwoWay: syncSessionTwoWayChannelFactory.Close(); break; case ServiceContract.IDuplexContract: duplexChannelFactory.Close(); break; case ServiceContract.IDuplexSessionContract: duplexSessionChannelFactory.Close(); break; default: Log.Trace(serviceContract + " type is not supported"); break; } } }
public static void IRequestChannel_Http_CustomBinding() { IChannelFactory <IRequestChannel> factory = null; IRequestChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); // Create the channel factory for the request-reply message exchange pattern. factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.DefaultCustomHttp_Address)); 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 *** \\ string replyMessageAction = replyMessage.Headers.Action; Assert.Equal(action + "Response", replyMessageAction); 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 override void Run(string sendTo) { IChannelFactory <IOutputChannel> factory = this.Binding.BuildChannelFactory <IOutputChannel>(); factory.Open(); if (this.Parameters.CreateChannel) { IOutputChannel channel = factory.CreateChannel(new EndpointAddress(sendTo)); this.SendMessages(channel); } factory.Close(); }
private void sendButton_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; // Creating the message to send TransmittedObject to = new TransmittedObject(); to.str = "Hello"; to.i = 5; XmlSerializerWrapper wrapper = new XmlSerializerWrapper(typeof(TransmittedObject)); Message m = Message.CreateMessage (MessageVersion.Soap11, "urn:test", to, wrapper); // Creating the channel to send the message BasicHttpBinding binding = new BasicHttpBinding(); BindingParameterCollection parameters = new BindingParameterCollection(); IChannelFactory <IRequestChannel> channelFactory = binding.BuildChannelFactory <IRequestChannel>(parameters); channelFactory.Open(); // Opening the channel IRequestChannel outChannel = channelFactory.CreateChannel (new EndpointAddress (new Uri("http://<<ServerAddress>>:<<PortNumber>>"))); outChannel.Open(TimeSpan.MaxValue); // Sending the Message and waiting for the reply Message reply = outChannel.Request(m, TimeSpan.MaxValue); // Deserializing and using the Message TransmittedObject to1 = reply.GetBody <TransmittedObject> (new XmlSerializerWrapper(typeof(TransmittedObject))); MessageBox.Show(to1.str + " " + to1.i.ToString()); // Cleaning up outChannel.Close(); channelFactory.Close(); Cursor.Current = Cursors.Default; }
private void SendMessage(object objectToSend) { IChannelFactory <IOutputChannel> channelFactory = Util.GetBinding().BuildChannelFactory <IOutputChannel>(); channelFactory.Open(); IOutputChannel proxy = channelFactory.CreateChannel(new EndpointAddress(Queue)); proxy.Open(); Message toSend = Message.CreateMessage(MessageVersion.Default, string.Empty, objectToSend); proxy.Send(toSend); toSend.Close(); channelFactory.Close(); }
static void Main(string[] args) { try { Options options = new Options(args); AmqpBinaryBinding binding = new AmqpBinaryBinding(); binding.BrokerHost = options.Broker; binding.BrokerPort = options.Port; binding.TransferMode = TransferMode.Streamed; IChannelFactory <IOutputChannel> factory = binding.BuildChannelFactory <IOutputChannel>(); factory.Open(); try { System.ServiceModel.EndpointAddress addr = options.Address; IOutputChannel sender = factory.CreateChannel(addr); sender.Open(); MyRawBodyWriter.Initialize(options.Content); DateTime end = DateTime.Now.Add(options.Timeout); System.ServiceModel.Channels.Message message; for (int count = 0; ((count < options.Count) || (options.Count == 0)) && ((options.Timeout == TimeSpan.Zero) || (end.CompareTo(DateTime.Now) > 0)); count++) { message = Message.CreateMessage(MessageVersion.None, "", new MyRawBodyWriter()); AmqpProperties props = new AmqpProperties(); props.ContentType = "text/plain"; string id = Guid.NewGuid().ToString() + ":" + count; props.PropertyMap.Add("spout-id", new AmqpString(id)); message.Properties["AmqpProperties"] = props; sender.Send(message); } } finally { factory.Close(); } } catch (Exception e) { Console.WriteLine("Spout: " + e); } }
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); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <param name="disposing">Disposes of the channel factory if set to true.</param> /// <remarks>You should use this method when finished with an instance of <see cref="ServiceClient{TService}"/>.</remarks> protected virtual void Dispose(bool disposing) { if (disposing) { if (_channelFactory != null) { try { if (_channelFactory.State != CommunicationState.Faulted) { _channelFactory.Close(); } else { _channelFactory.Abort(); } } catch (CommunicationException) { if (_channelFactory != null) { _channelFactory.Abort(); } } catch (TimeoutException) { if (_channelFactory != null) { _channelFactory.Abort(); } } catch (Exception) { if (_channelFactory != null) { _channelFactory.Abort(); } throw; } finally { _channelFactory = null; } } } }
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())); } }
public static void IRequestChannel_Https_NetHttpsBinding() { IChannelFactory <IRequestChannel> factory = null; IRequestChannel channel = null; Message replyMessage = null; try { // *** SETUP *** \\ NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport); // Create the channel factory factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection()); factory.Open(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps_Binary)); 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 *** \\ 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); } }
protected override void OnClose(TimeSpan timeout) { DateTime start = DateTime.Now; if (client_factory != null) { client_factory.Close(timeout - (DateTime.Now - start)); } peers.Clear(); resolver.Unregister(node.RegisteredId, timeout - (DateTime.Now - start)); node.SetOffline(); if (listener_host != null) { listener_host.Close(timeout - (DateTime.Now - start)); } node.RegisteredId = null; }