public HttpAcknowledgementInputChannel(IReplyChannel innerChannel, HttpAcknowledgementChannelListener listener, ReceiveContextSettings receiveContextSettings) : base(listener) { this.innerChannel = innerChannel; this.receiveContextSettings = receiveContextSettings; }
public ProtoBufMetaDataReplyChannel(EndpointAddress address, ChannelManagerBase parent, IReplyChannel innerChannel) : base(parent, innerChannel) { this._localAddress = address; _innerChannel = innerChannel; }
public DurableInstanceContextReplyChannel(ChannelManagerBase channelManager, ContextType contextType, IReplyChannel innerChannel) : base(channelManager, innerChannel) { this.contextType = contextType; this.innerReplyChannel = innerChannel; }
internal ReplyChannelBinder(IReplyChannel channel, Uri listenUri) { if (channel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channel"); } this.channel = channel; this.listenUri = listenUri; }
internal ReplyChannelBinder(IReplyChannel channel, Uri listenUri) { if (channel == null) { Fx.Assert("ReplyChannelBinder.ReplyChannelBinder: (channel != null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channel"); } _channel = channel; _listenUri = listenUri; }
public void Start(ServerBindingContext ctx) { if (1 == Interlocked.Increment(ref m_refcount)) { m_requestStop = false; m_replyChannel = m_binding.CreateServerChannel(ctx); m_replyChannel.Open(); m_thread = new Thread(new ThreadStart(this.Listen)); m_thread.Start(); } }
public async Task <IChannelBinder> AcceptAsync(CancellationToken token) { IReplyChannel channel = await listener.AcceptChannelAsync(token); if (channel == null) { return(null); } return(null); //return new ReplyChannelBinder(channel, listener.Uri); }
private static Exception CreateReceiveRequestTimedOutException(IReplyChannel channel, TimeSpan timeout) { if (channel.LocalAddress != null) { return(new TimeoutException(SR.ReceiveRequestTimedOut(channel.LocalAddress.Uri.AbsoluteUri, timeout))); } else { return(new TimeoutException(SR.ReceiveRequestTimedOutNoLocalAddress(timeout))); } }
public IChannelBinder Accept(TimeSpan timeout) { IReplyChannel channel = _listener.AcceptChannel(timeout); if (channel == null) { return(null); } return(new ReplyChannelBinder(channel, _listener.Uri)); }
public IChannelBinder EndAccept(IAsyncResult result) { IReplyChannel channel = _listener.EndAcceptChannel(result); if (channel == null) { return(null); } return(new ReplyChannelBinder(channel, _listener.Uri)); }
static void RunService() { //Step1: Create a custom binding with just TCP. BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); //Step2: Use the binding to build the channel listener. IChannelListener <IReplyChannel> listener = binding.BuildChannelListener <IReplyChannel>( new Uri("http://localhost:8080/channelapp"), new BindingParameterCollection()); //Step3: Listening for messages. listener.Open(); Console.WriteLine( "Listening for incoming channel connections"); //Wait for and accept incoming connections. IReplyChannel channel = listener.AcceptChannel(); Console.WriteLine("Channel accepted. Listening for messages"); //Open the accepted channel. channel.Open(); //Wait for and receive a message from the channel. RequestContext request = channel.ReceiveRequest(); //Step4: Reading the request message. Message message = request.RequestMessage; Console.WriteLine("Message received"); Console.WriteLine("Message action: {0}", message.Headers.Action); string data = message.GetBody <string>(); Console.WriteLine("Message content: {0}", data); //Send a reply. Message replymessage = Message.CreateMessage( binding.MessageVersion, "http://contoso.com/someotheraction", data); request.Reply(replymessage); //Step5: Closing objects. //Do not forget to close the message. message.Close(); //Do not forget to close RequestContext. request.Close(); //Do not forget to close channels. channel.Close(); //Do not forget to close listeners. listener.Close(); }
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 void AcceptChannel_Returns_Null_If_Inner_Listener_Returns_Null() { MockChannelListener innerListener = new MockChannelListener(true /* return null channel */); HttpMessageEncodingChannelListener listener = new HttpMessageEncodingChannelListener(innerListener); listener.Open(); IReplyChannel replyChannel = listener.AcceptChannel(); Assert.IsNull(replyChannel, "HttpMessageEncodingChannelListener.AcceptChannel should have returned null since the inner listener returned null."); }
protected override TChannel OnEndAcceptChannel(IAsyncResult result) { this.Print("OnEndAcceptChannel()"); IReplyChannel innerChannel = (IReplyChannel)this.InnerChannelListener.EndAcceptChannel(result); if (null != innerChannel) { return(new SimpleReplyChannel(this, innerChannel) as TChannel); } return(null); }
protected override TChannel OnAcceptChannel(TimeSpan timeout) { this.Print("OnAcceptChannel()"); IReplyChannel innerChannel = (IReplyChannel)this.InnerChannelListener.AcceptChannel(timeout); if (null != innerChannel) { return(new SimpleReplyChannel(this, innerChannel) as TChannel); } return(null); }
protected ReceiveAsyncResultBase(IReplyChannel innerChannel, TimeSpan timeout, bool validateHeader, AsyncCallback callback, object state) : base(callback, state) { this.innerChannel = innerChannel; this.timeoutHelper = new TimeoutHelper(timeout); this.validateHeader = validateHeader; IAsyncResult result = this.OnBeginReceiveRequest(this.timeoutHelper.RemainingTime(), onReceiveRequest, this); if (result.CompletedSynchronously && this.HandleReceiveRequestComplete(result)) { base.Complete(true); } }
// private private WsUdpServiceHost() { m_threadManager = new WsThreadManager(5, "Udp"); m_serviceEndpoints = new WsServiceEndpoints(); m_refcount = 0; m_binding = null; m_replyChannel = null; UdpTransportBindingElement transport = new UdpTransportBindingElement(new UdpTransportBindingConfig(WsDiscovery.WsDiscoveryAddress, WsDiscovery.WsDiscoveryPort, m_ignoreLocalRequests)); m_binding = new CustomBinding(transport); }
public HelpReceiveRequestAsyncResult(IReplyChannel channel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeout = timeout; IAsyncResult result = channel.BeginTryReceiveRequest(timeout, onReceiveRequest, this); if (result.CompletedSynchronously) { this.HandleReceiveRequestComplete(result); base.Complete(true); } }
public IChannelListenerPage() { InitializeComponent(); ///监听者 IChannelListener <IReplyChannel> listener = binding.BuildChannelListener <IReplyChannel>(new Uri("http://localhost:9090/RequestReplyService"), new BindingParameterCollection()); listener.Open();//打开 //创建IReplyChannel IReplyChannel replyChannel = listener.AcceptChannel(); replyChannel.Open();//打开IReplyChannel应答通道 }
public void AcceptChannel_Returns_HttpMessageEncodingReplyChannel() { MockChannelListener innerListener = new MockChannelListener(); HttpMessageEncodingChannelListener listener = new HttpMessageEncodingChannelListener(innerListener); listener.Open(); IReplyChannel replyChannel = listener.AcceptChannel(); Assert.IsNotNull(replyChannel, "HttpMessageEncodingChannelListener.AcceptChannel should not have returned null."); Assert.IsInstanceOfType(replyChannel, typeof(HttpMessageEncodingReplyChannel), "HttpMessageEncodingChannelListener.AcceptChannel should have returned an HttpMessageEncodingReplyChannel."); }
protected override void OnOpen(TimeSpan timeout) { // Because the inner listener is a Datagram (singleton) listener, we // accept the singleton channel and then dispose of the listener because // the lifetimes are decoupled. TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); this.innerChannelListener.Open(timeoutHelper.RemainingTime()); this.innerChannel = this.innerChannelListener.AcceptChannel(timeoutHelper.RemainingTime()); this.innerChannel.Open(timeoutHelper.RemainingTime()); this.innerChannelListener.Close(timeoutHelper.RemainingTime()); }
static void RunListener (IReplyChannel reply) { if (!reply.WaitForRequest (TimeSpan.FromSeconds (10))) { Console.WriteLine ("No request reached here."); return; } Console.WriteLine ("Receiving request ..."); RequestContext ctx = reply.ReceiveRequest (); if (ctx == null) return; Console.WriteLine ("Starting reply ..."); ctx.Reply (Message.CreateMessage (MessageVersion.Default, "Ack")); }
private static Exception CreateReceiveRequestTimedOutException(IReplyChannel channel, TimeSpan timeout) { if (channel.LocalAddress == null) { string receiveRequestTimedOutNoLocalAddress = Resources.ReceiveRequestTimedOutNoLocalAddress; object[] objArray = new object[] { timeout }; return(new TimeoutException(Microsoft.ServiceBus.SR.GetString(receiveRequestTimedOutNoLocalAddress, objArray))); } string receiveRequestTimedOut = Resources.ReceiveRequestTimedOut; object[] absoluteUri = new object[] { channel.LocalAddress.Uri.AbsoluteUri, timeout }; return(new TimeoutException(Microsoft.ServiceBus.SR.GetString(receiveRequestTimedOut, absoluteUri))); }
private static RequestContext HelpReceiveRequest(IReplyChannel channel, TimeSpan timeout) { RequestContext requestContext; if (channel.TryReceiveRequest(timeout, out requestContext)) { return(requestContext); } else { throw FxTrace.Exception.AsError(UdpReplyChannel.CreateReceiveRequestTimedOutException(channel, timeout)); } }
public HelpReceiveRequestAsyncResult(IReplyChannel channel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeout = timeout; IAsyncResult asyncResult = channel.BeginTryReceiveRequest(timeout, Microsoft.ServiceBus.Channels.ReplyChannel.HelpReceiveRequestAsyncResult.onReceiveRequest, this); if (!asyncResult.CompletedSynchronously) { return; } this.HandleReceiveRequestComplete(asyncResult); base.Complete(true); }
public void AcceptChannel_Calls_The_Inner_Listener_With_Timeout() { MockChannelListener innerListener = new MockChannelListener(); HttpMessageEncodingChannelListener listener = new HttpMessageEncodingChannelListener(innerListener); listener.Open(); TimeSpan timeout = new TimeSpan(0, 2, 0); IReplyChannel replyChannel = listener.AcceptChannel(timeout); Assert.IsTrue(innerListener.OnAcceptChannelCalled, "HttpMessageEncodingChannelListener.AcceptChannel should have called AcceptChannel on the inner listener."); Assert.AreEqual(innerListener.TimeoutParameter, timeout, "HttpMessageEncodingChannelListener.AcceptChannel should have passed along the same timeout instance to the inner listener."); }
internal static RequestContext HelpReceiveRequest(IReplyChannel channel, TimeSpan timeout) { RequestContext requestContext; if (channel.TryReceiveRequest(timeout, out requestContext)) { return(requestContext); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( ReplyChannel.CreateReceiveRequestTimedOutException(channel, timeout)); } }
static void Main(string[] args) { try { //建立和发送端相同的通道栈 BindingElement[] bindingElements = new BindingElement[2]; bindingElements[0] = new TextMessageEncodingBindingElement(); bindingElements[1] = new HttpTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); //建立ChannelListener IChannelListener <IReplyChannel> listener = binding.BuildChannelListener <IReplyChannel>( new Uri("http://localhost:9090/RequestReplyService"), new BindingParameterCollection()); listener.Open(); //打开监听 //创建IReplyChannel IReplyChannel replyChannel = listener.AcceptChannel(); replyChannel.Open(); //打开通道 Console.WriteLine("开始接收消息"); //接收并打印消息 RequestContext requestContext = replyChannel.ReceiveRequest(); //会堵塞在这里 Console.WriteLine("接收到一条消息, action为{0}, body为{1}", requestContext.RequestMessage.Headers.Action, requestContext.RequestMessage.GetBody <string>()); //创建返回消息 Message response = Message.CreateMessage(binding.MessageVersion, "response", "response body"); //发送返回消息 requestContext.Reply(response); requestContext.Close(); replyChannel.Close(); listener.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }
internal static async Task <RequestContext> HelpReceiveRequestAsync(IReplyChannel channel, CancellationToken token) { var result = await channel.TryReceiveRequestAsync(token); if (result.Success) { return(result.Result); } else { // TODO: Fix timeout value throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( ReplyChannel.CreateReceiveRequestTimedOutException(channel, TimeSpan.Zero)); } }
void OnReceive(IAsyncResult result) { if (result.CompletedSynchronously) { return; } IReplyChannel channel = (IReplyChannel)result.AsyncState; RequestContext context = channel.EndReceiveRequest(result); if (HandleRequest(channel, context)) { ReceiveRequest(channel); } }
public void AcceptRequest(IAsyncResult ar) { IReplyChannel channel = ar.AsyncState as IReplyChannel; try { RequestContext context = channel.EndReceiveRequest(ar); channel.BeginReceiveRequest(AcceptRequest, channel); ProcessRequest(context); } catch (TimeoutException) { channel.BeginReceiveRequest(AcceptRequest, channel); } }
void AcceptCallback(object state) { IChannelListener <IReplyChannel> listener = (IChannelListener <IReplyChannel>)state; this.acceptedChannel = listener.AcceptChannel(TimeSpan.MaxValue); if (this.acceptedChannel != null) { this.acceptedChannel.Open(); ReceiveRequest(this.acceptedChannel); } else { listener.Close(); } }
public void EndAcceptChannel_Returns_Null_If_The_Inner_Listener_Returns_Null() { MockChannelListener innerListener = new MockChannelListener(true /* return null channel */); HttpMessageEncodingChannelListener listener = new HttpMessageEncodingChannelListener(innerListener); listener.Open(); object state = new object(); AsyncCallback callback = MockAsyncCallback.Create(); TimeSpan timeout = new TimeSpan(0, 2, 0); IAsyncResult result = listener.BeginAcceptChannel(timeout, callback, state); IReplyChannel channel = listener.EndAcceptChannel(result); Assert.IsNull(channel, "HttpMessageEncodingChannelListener.EndAcceptChannel should have returned null since the inner listener returned null."); }
private void BasicChannelTestB(bool customBinding) { IChannelListener <IReplyChannel> listener = null; IReplyChannel channel = null; ManualResetEvent done = new ManualResetEvent(false); Thread t = null; try { channel = this.OpenChannel(customBinding, out listener); Assert.IsNotNull(channel); Assert.IsNotNull(listener); t = new Thread(BasicChannelTests.SubmitRequests); t.Start(done); for (var cnt = 0; cnt < TestServiceCommon.Iterations; cnt++) { RequestContext context; if (channel.TryReceiveRequest(TestServiceCommon.DefaultHostTimeout, out context)) { this.SendResponse(context); } else { Assert.Fail("TryReceiveRequest failed."); } } channel.Close(TestServiceCommon.DefaultHostTimeout); listener.Close(TestServiceCommon.DefaultHostTimeout); } catch (Exception e) { channel.Abort(); listener.Abort(); Assert.Fail("Unexpected exception: " + e); } finally { if (t != null && !done.WaitOne(TestServiceCommon.DefaultHostTimeout)) { t.Abort(); } done.Dispose(); } }
private static bool EndTryAcceptChannel(IAsyncResult result, out IReplyChannel channel) { Contract.Assert(result != null); CompletedAsyncResult <bool> handlerResult = result as CompletedAsyncResult <bool>; if (handlerResult != null) { channel = null; return(CompletedAsyncResult <bool> .End(handlerResult)); } else { try { HttpSelfHostServer server = (HttpSelfHostServer)result.AsyncState; Contract.Assert(server != null); Contract.Assert(server._listener != null); channel = server._listener.EndAcceptChannel(result); return(true); } catch (CommunicationObjectAbortedException) { channel = null; return(true); } catch (CommunicationObjectFaultedException) { channel = null; return(true); } catch (TimeoutException) { channel = null; return(false); } catch (CommunicationException) { channel = null; return(false); } catch { channel = null; return(false); } } }
internal async Task <IServiceChannelDispatcher> GetAuthChannelDispatcher(IReplyChannel outerChannel) { if (_securityAuthServiceChannelDispatcher == null) { lock (ThisLock) { if (_channelTask == null) { _channelTask = SecurityAuthServiceDispatcher.CreateServiceChannelDispatcherAsync(outerChannel); } } _securityAuthServiceChannelDispatcher = await _channelTask; Thread.MemoryBarrier(); } return(_securityAuthServiceChannelDispatcher); }
public Fetch(IReplyChannel<int?> channel) { this.Channel = channel; }
public ReceiveRequestAsyncResult(IReplyChannel channel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeout = timeout; IAsyncResult result = channel.BeginTryReceiveRequest(timeout, onReceiveRequest, this); if (!result.CompletedSynchronously) { return; } OnReceiveRequestCore(result); base.Complete(true); }
void AcceptCallback(object state) { IChannelListener<IReplyChannel> listener = (IChannelListener<IReplyChannel>)state; this.acceptedChannel = listener.AcceptChannel(TimeSpan.MaxValue); if (this.acceptedChannel != null) { this.acceptedChannel.Open(); ReceiveRequest(this.acceptedChannel); } else { listener.Close(); } }
void ReceiveRequest(IReplyChannel channel) { for (; ; ) { IAsyncResult result = channel.BeginReceiveRequest(TimeSpan.MaxValue, this.onReceive, channel); if (!result.CompletedSynchronously) break; RequestContext context = channel.EndReceiveRequest(result); if (!HandleRequest(channel, context)) { break; } } }
bool HandleRequest(IReplyChannel channel, RequestContext context) { if (context == null) { channel.Close(); return false; } try { serviceManager.HandleRequest(context); } catch (CommunicationException) { context.Abort(); } finally { context.Close(); } return true; }
/// <summary> /// Initializes a new instance of the <see cref="ChannelContext"/> class. /// </summary> /// <param name="server">The host to associate with this context.</param> /// <param name="channel">The channel to associate with this channel.</param> public ChannelContext(AzureServiceBusHttpServer server, IReplyChannel channel) { Contract.Assert(server != null); Contract.Assert(channel != null); Server = server; Channel = channel; }
public MyReplyChannel(ChannelManagerBase channelManager, IReplyChannel innerChannel) : base(channelManager) { this.InnerChannel = innerChannel; }
public SimpleReplyChannel(ChannelManagerBase channelManager, IReplyChannel innerChannel) : base(channelManager, (ChannelBase)innerChannel) { }
private static bool EndTryAcceptChannel(IAsyncResult result, out IReplyChannel channel) { Contract.Assert(result != null); CompletedAsyncResult<bool> handlerResult = result as CompletedAsyncResult<bool>; if (handlerResult != null) { channel = null; return CompletedAsyncResult<bool>.End(handlerResult); } else { try { HttpSelfHostServer server = (HttpSelfHostServer)result.AsyncState; Contract.Assert(server != null); Contract.Assert(server._listener != null); channel = server._listener.EndAcceptChannel(result); return true; } catch (CommunicationObjectAbortedException) { channel = null; return true; } catch (CommunicationObjectFaultedException) { channel = null; return true; } catch (TimeoutException) { channel = null; return false; } catch (CommunicationException) { channel = null; return false; } catch { channel = null; return false; } } }
/// <summary> /// Initializes a new instance of the <see cref="ChannelContext"/> class. /// </summary> /// <param name="server">The host to associate with this context.</param> /// <param name="channel">The channel to associate with this channel.</param> public ChannelContext(HttpSelfHostServer server, IReplyChannel channel) { Contract.Assert(server != null); Contract.Assert(channel != null); Server = server; Channel = channel; }
public SimpleReplyChannel(ChannelManagerBase channelManager, IReplyChannel innerChannel) : base(channelManager, (ChannelBase)innerChannel) { this.Print("SimpleReplyChannel()"); }