BuildChannelListener(TChannel) Method

BindingElement.BuildChannelListener<TChannel> Method (BindingContext)

 

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

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.

Type Parameters

TChannel

The type of channel the listener is built to accept.

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();

.NET Framework
Available since 3.0
Return to top
Show:
© 2016 Microsoft