BindingElement.BuildChannelListener<TChannel> Method
.NET Framework 4.5
Initializes a channel listener to accept channels of a specified type from the binding context.
Namespace: System.ServiceModel.Channels
Assembly: System.ServiceModel (in System.ServiceModel.dll)
public virtual IChannelListener<TChannel> BuildChannelListener<TChannel>( BindingContext context ) where TChannel : class, IChannel
Type Parameters
- TChannel
The type of channel the listener is built to accept.
Parameters
- context
- Type: System.ServiceModel.Channels.BindingContext
The BindingContext that provides context for the binding element.
Return Value
Type: System.ServiceModel.Channels.IChannelListener<TChannel>The IChannelListener<TChannel> of type IChannel initialized from the context.
| Exception | Condition |
|---|---|
| ArgumentNullException | context is null. |
CustomBinding binding = new CustomBinding(); HttpTransportBindingElement element = new HttpTransportBindingElement(); BindingParameterCollection parameters = new BindingParameterCollection(); Uri baseAddress = new Uri("http://localhost:8000/ChannelApp"); String relAddress = "http://localhost:8000/ChannelApp/service"; BindingContext context = new BindingContext(binding, parameters, baseAddress, relAddress, ListenUriMode.Explicit); IChannelListener<IReplyChannel> listener = element.BuildChannelListener<IReplyChannel>(context); listener.Open(); IReplyChannel channel = listener.AcceptChannel(); channel.Open(); RequestContext request = channel.ReceiveRequest(); Message msg = request.RequestMessage; Console.WriteLine("Message Received"); Console.WriteLine("Message Action: {0}", msg.Headers.Action); if (msg.Headers.Action == "hello") { Message reply = Message.CreateMessage(MessageVersion.Default, "wcf"); request.Reply(reply); } msg.Close(); channel.Close(); listener.Close();
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.