public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) { var timeout = ((IDefaultCommunicationTimeouts)this.Manager).ReceiveTimeout; CheckAndMakeMetaDataRequest(message, timeout); return(_innerChannel.BeginRequest(message, callback, state)); }
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 void FullRequest() { EndpointIdentity identity = new X509CertificateEndpointIdentity(new X509Certificate2("Test/Resources/test.pfx", "mono")); EndpointAddress address = new EndpointAddress(new Uri("stream:dummy"), identity); Message mreq = Message.CreateMessage(MessageVersion.Default, "myAction"); Message mreply = null; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; // listener setup ReplyHandler replyHandler = delegate(Message rinput) { mreply = rinput; }; RequestReceiver receiver = delegate() { return(mreq); }; IChannelListener <IReplyChannel> listener = CreateListener(replyHandler, receiver); listener.Open(); IReplyChannel reply = listener.AcceptChannel(); reply.Open(); RequestSender reqHandler = delegate(Message input) { try { // sync version somehow causes an infinite loop (!?) RequestContext ctx = reply.EndReceiveRequest(reply.BeginReceiveRequest(TimeSpan.FromSeconds(5), null, null)); // RequestContext ctx = reply.ReceiveRequest (TimeSpan.FromSeconds (5)); Console.Error.WriteLine("Acquired RequestContext."); ctx.Reply(input); } catch (Exception ex) { Console.Error.WriteLine("ERROR during processing a request in FullRequest()"); Console.Error.WriteLine(ex); Console.Error.Flush(); throw; } return(mreply); }; CustomBinding b = CreateBinding(reqHandler); IRequestChannel ch = ChannelFactory <IRequestChannel> .CreateChannel(b, address); ch.Open(); Console.Error.WriteLine("**** starting a request ****"); IAsyncResult async = ch.BeginRequest(mreq, null, null); Console.Error.WriteLine("**** request started. ****"); Message res = ch.EndRequest(async); }
public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state) { // Apply the context before sending the request. ApplyContext(message); return(innerRequestChannel.BeginRequest(message, timeout, callback, state)); }
public static void ChannelShape_TypedProxy_InvokeIRequestChannelAsync() { string address = Endpoints.DefaultCustomHttp_Address; StringBuilder errorBuilder = new StringBuilder(); try { CustomBinding binding = new CustomBinding(new BindingElement[] { new TextMessageEncodingBindingElement(MessageVersion.Default, Encoding.UTF8), new HttpTransportBindingElement() }); EndpointAddress endpointAddress = new EndpointAddress(address); // Create the channel factory for the request-reply message exchange pattern. var factory = new ChannelFactory <IRequestChannel>(binding, endpointAddress); // Create the channel. IRequestChannel channel = factory.CreateChannel(); 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. IAsyncResult ar = channel.BeginRequest(requestMessage, null, null); Message replyMessage = channel.EndRequest(ar); string replyMessageAction = replyMessage.Headers.Action; if (!string.Equals(replyMessageAction, action + "Response")) { errorBuilder.AppendLine(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)) { 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: InvokeIRequestChannelViaProxyAsync FAILED with the following errors: {0}", errorBuilder)); }
//[WcfFact] //[OuterLoop] public static void IRequestChannel_Async_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()); Task.Factory.FromAsync(factory.BeginOpen, factory.EndOpen, TaskCreationOptions.None).GetAwaiter().GetResult(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.DefaultCustomHttp_Address)); Task.Factory.FromAsync(channel.BeginOpen, channel.EndOpen, TaskCreationOptions.None).GetAwaiter().GetResult(); // 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 = Task.Factory.FromAsync((asyncCallback, o) => channel.BeginRequest(requestMessage, asyncCallback, o), channel.EndRequest, TaskCreationOptions.None).GetAwaiter().GetResult(); // *** 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(); Task.Factory.FromAsync(channel.BeginClose, channel.EndClose, TaskCreationOptions.None).GetAwaiter().GetResult(); Task.Factory.FromAsync(factory.BeginClose, factory.EndClose, TaskCreationOptions.None).GetAwaiter().GetResult(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }
public RequestAsyncResult(IRequestChannel innerChannel, Message message, TimeSpan timeout, AsyncCallback onRequestDone, AsyncCallback callback, object state, DependencyTelemetry telemetry) : base(onRequestDone, callback, state, telemetry) { this.InnerChannel = innerChannel; this.OriginalResult = innerChannel.BeginRequest(message, timeout, OnComplete, this); if (this.OriginalResult.CompletedSynchronously) { this.Reply = innerChannel.EndRequest(this.OriginalResult); this.CompleteSynchronously(); } }
//[WcfFact] //[OuterLoop] public static void IRequestChannel_Async_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()); Task.Factory.FromAsync(factory.BeginOpen, factory.EndOpen, TaskCreationOptions.None).GetAwaiter().GetResult(); // Create the channel. channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_Basic)); Task.Factory.FromAsync(channel.BeginOpen, channel.EndOpen, TaskCreationOptions.None).GetAwaiter().GetResult(); // 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 = Task.Factory.FromAsync((asyncCallback, o) => channel.BeginRequest(requestMessage, asyncCallback, o), channel.EndRequest, TaskCreationOptions.None).GetAwaiter().GetResult(); // *** 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(); Task.Factory.FromAsync(channel.BeginClose, channel.EndClose, TaskCreationOptions.None).GetAwaiter().GetResult(); Task.Factory.FromAsync(factory.BeginClose, factory.EndClose, TaskCreationOptions.None).GetAwaiter().GetResult(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }
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 IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state) { return(_channel.BeginRequest(message, timeout, callback, state)); }
public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) { return(inner.BeginRequest(message, callback, state)); }
public void AsynchronousRequest() { byte[] data = new byte[36]; Random rndGen = new Random(); rndGen.NextBytes(data); Message input = Formatting.BytesToMessage(data); ManualResetEvent evt = new ManualResetEvent(false); Uri serverUri = new Uri(SizedTcpTransportBindingElement.SizedTcpScheme + "://" + Environment.MachineName + ":" + Port); object channel = ReflectionHelper.CreateInstance( typeof(SizedTcpTransportBindingElement), "JsonRpcOverTcp.Channels.SizedTcpRequestChannel", new ByteStreamMessageEncodingBindingElement().CreateMessageEncoderFactory().Encoder, BufferManager.CreateBufferManager(int.MaxValue, int.MaxValue), Mocks.GetChannelManagerBase(), new EndpointAddress(serverUri), serverUri); ChannelBase channelBase = (ChannelBase)channel; IRequestChannel requestChannel = (IRequestChannel)channel; channelBase.Open(); object state = new object(); bool success = true; requestChannel.BeginRequest(input, new AsyncCallback(delegate(IAsyncResult asyncResult) { try { if (!Object.ReferenceEquals(asyncResult.AsyncState, state)) { success = false; Console.WriteLine("Error, state not preserved"); } else { Message output = requestChannel.EndRequest(asyncResult); try { byte[] outputBytes = Formatting.MessageToBytes(output); Assert.Equal(data, outputBytes, new ArrayComparer <byte>()); } catch (Exception e) { Console.WriteLine("Error: " + e); success = false; } } } finally { evt.Set(); } }), state); evt.WaitOne(); Assert.True(success, "Error in callback"); channelBase.Close(); }
public IAsyncResult BeginRequest(System.ServiceModel.Channels.Message message, TimeSpan timeout, AsyncCallback callback, object state) { return(_innerChannel.BeginRequest(message, timeout, callback, state)); }
public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) => _innerChannel.BeginRequest(message, callback, state);
// Plug in IClientMessageInspector in the following three methods public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state) { messageInspector.BeforeSendRequest(ref message, null); return(innerChannel.BeginRequest(message, timeout, callback, state)); }
protected virtual IAsyncResult OnBeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state) { return(inner.BeginRequest(message, timeout, callback, state)); }
public IAsyncResult BeginRequest(Message message, AsyncCallback callback, object state) { return(_innerChannel.BeginRequest(Wrap(message), callback, state)); }
public static void ChannelShape_TypedProxy_InvokeIRequestChannelAsync() { CustomBinding customBinding = null; ChannelFactory <IRequestChannel> factory = null; EndpointAddress endpointAddress = null; IRequestChannel channel = null; Message requestMessage = null; Message replyMessage = null; string replyMessageAction = null; string actualResponse = null; try { // *** SETUP *** \\ customBinding = new CustomBinding(new BindingElement[] { new TextMessageEncodingBindingElement(MessageVersion.Default, Encoding.UTF8), new HttpTransportBindingElement() }); endpointAddress = new EndpointAddress(Endpoints.DefaultCustomHttp_Address); // Create the channel factory for the request-reply message exchange pattern. factory = new ChannelFactory <IRequestChannel>(customBinding, endpointAddress); // Create the channel. channel = factory.CreateChannel(); channel.Open(); // Create the Message object to send to the service. requestMessage = Message.CreateMessage( customBinding.MessageVersion, action, new CustomBodyWriter(clientMessage)); string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply."; // *** EXECUTE *** \\ // Send the Message and receive the Response. IAsyncResult ar = channel.BeginRequest(requestMessage, null, null); replyMessage = channel.EndRequest(ar); replyMessageAction = replyMessage.Headers.Action; // *** VALIDATE *** \\ Assert.True(String.Equals(replyMessageAction, action + "Response"), String.Format("A response was received from the Service but it was not the expected Action, expected: {0} actual: {1}", action + "Response", replyMessageAction)); // *** EXECUTE *** \\ var replyReader = replyMessage.GetReaderAtBodyContents(); actualResponse = replyReader.ReadElementContentAsString(); // *** VALIDATE *** \\ Assert.True(String.Equals(actualResponse, expectedResponse), String.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse)); // *** CLEANUP *** \\ replyMessage.Close(); channel.Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ replyMessage.Close(); ScenarioTestHelpers.CloseCommunicationObjects(channel, factory); } }