ChannelFactory

ChannelFactory

 

 

The following example illustrates how to use the ChannelFactory class to create a channel on the client to send messages with the service endpoint.

 

In order to create and manage channels, you need to import the System.ServiceModel.Channels namespace.

 

Let’s take a look at the following code snippet.

 

ChannelFactory<TCP.IServiceClass> factory = new

ChannelFactory<TCP.IServiceClass>(“WSHttpBinding_IServiceClass”);

TCP.IServiceClass channel = factory.CreateChannel();

 

The above code is the construction and management of the channel. The first line initializes a new instance of the ChannelFactory class. This is necessary to create the channel. In the constructor of this class, you pass the name of the endpoint in which this channel will communicate. The second line creates the channel (Service Contract) which is used to communicate with the client.

 

Next is to call the exposed method, then release ChannelFacotry instance.

result = channel.AddNumbers(val1, val2);

factory.Close();

 

 

原文地址:https://www.cnblogs.com/rickie/p/1060316.html