Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

ChannelFactory<TChannel> Class

A factory that creates channels of different types that are used by clients to send messages to variously configured service endpoints.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
public class ChannelFactory<TChannel> : ChannelFactory, 
	IChannelFactory<TChannel>, IChannelFactory, ICommunicationObject

Type Parameters

TChannel

The type of channel produced by the channel factory. This type must be either IOutputChannel or IRequestChannel.

The ChannelFactory<TChannel> type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneChannelFactory<TChannel>(String)Initializes a new instance of the ChannelFactory<TChannel> class and configures the endpoint.
Protected methodChannelFactory<TChannel>(Type)Initializes a new instance of the ChannelFactory<TChannel> class.
Public methodSupported by Silverlight for Windows PhoneChannelFactory<TChannel>(Binding, EndpointAddress)Initializes a new instance of the ChannelFactory<TChannel> class with a specified endpoint address and binding configuration.
Public methodSupported by Silverlight for Windows PhoneChannelFactory<TChannel>(String, EndpointAddress)Initializes a new instance of the ChannelFactory<TChannel> class with a specified endpoint address and endpoint configuration.
Top
  NameDescription
Public propertySupported by Silverlight for Windows PhoneCredentialsGets the credentials used by clients to communicate a service endpoint over the channels produced by the factory. (Inherited from ChannelFactory.)
Protected propertySupported by Silverlight for Windows PhoneDefaultCloseTimeoutGets the default interval of time provided for a close operation to complete. (Inherited from ChannelFactory.)
Protected propertySupported by Silverlight for Windows PhoneDefaultOpenTimeoutGets the default interval of time provided for an open operation to complete. (Inherited from ChannelFactory.)
Public propertySupported by Silverlight for Windows PhoneEndpointGets the service endpoint to which the channels produced by the factory connect. (Inherited from ChannelFactory.)
Protected propertySupported by Silverlight for Windows PhoneIsDisposedGets a value that indicates whether the communication object has been disposed. (Inherited from CommunicationObject.)
Public propertySupported by Silverlight for Windows PhoneStateGets a value that indicates the current state of the communication object. (Inherited from CommunicationObject.)
Protected propertySupported by Silverlight for Windows PhoneThisLockGets the mutually exclusive lock that protects the class instance during a state transition. (Inherited from CommunicationObject.)
Top
  NameDescription
Public methodSupported by Silverlight for Windows PhoneAbortCauses a communication object to transition immediately from its current state into the closing state. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneApplyConfigurationInitializes the channel factory with the behaviors provided by a specified configuration file and with those in the service endpoint of the channel factory. (Inherited from ChannelFactory.)
Public methodSupported by Silverlight for Windows PhoneBeginClose(AsyncCallback, Object)Begins an asynchronous operation to close a communication object. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneBeginClose(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to close a communication object with a specified timeout. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneBeginOpen(AsyncCallback, Object)Begins an asynchronous operation to close a communication object. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneBeginOpen(TimeSpan, AsyncCallback, Object)Begins an asynchronous operation to close a communication object within a specified interval of time. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneClose()Causes a communication object to transition from its current state into the closed state. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneClose(TimeSpan)Causes a communication object to transition from its current state into the closed state within a specified interval of time. (Inherited from CommunicationObject.)
Public methodCreateChannel()Creates a channel that is used to send messages to a service.
Public methodSupported by Silverlight for Windows PhoneCreateChannel(EndpointAddress)Creates a channel that is used to send messages to a service at a specific endpoint address.
Public methodSupported by Silverlight for Windows PhoneCreateChannel(EndpointAddress, Uri)Creates a channel that is used to send messages to a service at a specific endpoint address through a specified transport address.
Protected methodSupported by Silverlight for Windows PhoneCreateDescriptionCreates a description of the service endpoint. (Overrides ChannelFactory.CreateDescription().)
Protected methodSupported by Silverlight for Windows PhoneCreateFactoryBuilds the channel factory for the current endpoint of the factory. (Inherited from ChannelFactory.)
Public methodSupported by Silverlight for Windows PhoneEndCloseCompletes an asynchronous operation to close a communication object. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneEndOpenCompletes an asynchronous operation to open a communication object. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneEnsureOpenedOpens the current channel factory if it is not yet opened. (Inherited from ChannelFactory.)
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneFaultCauses a communication object to transition from its current state into the faulted state. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneGetCommunicationObjectTypeGets the type of communication object. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetProperty<T>Returns the typed object requested, if present, from the appropriate layer in the channel stack, or null if not present. (Inherited from ChannelFactory.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodInitializeEndpoint(ServiceEndpoint)Initializes the service endpoint of the channel factory with a specified service endpoint. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneInitializeEndpoint(Binding, EndpointAddress)Initializes the service endpoint of the channel factory with a specified binding and address. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneInitializeEndpoint(String, EndpointAddress)Initializes the service endpoint of the channel factory with a specified address and configuration. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneOnAbortTerminates the inner channel factory of the current channel factory. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnBeginCloseBegins an asynchronous close operation on the inner channel factory of the current channel factory that has a state object associated with it. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnBeginOpenBegins an asynchronous open operation on the inner channel factory of the current channel factory that has a state object associated with it. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnCloseCalls close on the inner channel factory with a specified time-out for the completion of the operation. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnClosedInvoked during the transition of a communication object into the closing state. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneOnClosingInvoked during the transition of a communication object into the closing state. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneOnEndCloseCompletes an asynchronous close operation on the inner channel factory of the current channel factory. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnEndOpenCompletes an asynchronous open operation on the inner channel factory of the current channel factory. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnFaultedInserts processing on a communication object after it transitions to the faulted state due to the invocation of a synchronous fault operation. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneOnOpenCalls open on the inner channel factory of the current channel factory with a specified time-out for the completion of the operation. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnOpenedInitializes a read-only copy of the ClientCredentials object for the channel factory. (Inherited from ChannelFactory.)
Protected methodSupported by Silverlight for Windows PhoneOnOpeningBuilds the inner channel factory for the current channel. (Inherited from ChannelFactory.)
Public methodSupported by Silverlight for Windows PhoneOpen()Causes a communication object to transition from the created state into the opened state. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneOpen(TimeSpan)Causes a communication object to transition from the created state into the opened state within a specified interval of time. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneThrowIfDisposedThrows an exception if the communication object is disposed. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneThrowIfDisposedOrImmutableThrows an exception if the communication object the State property is not set to the Created state. (Inherited from CommunicationObject.)
Protected methodSupported by Silverlight for Windows PhoneThrowIfDisposedOrNotOpenThrows an exception if the communication object is not in the Opened state. (Inherited from CommunicationObject.)
Public methodSupported by Silverlight for Windows PhoneToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public eventSupported by Silverlight for Windows PhoneClosedOccurs when a communication object transitions into the closed state. (Inherited from CommunicationObject.)
Public eventSupported by Silverlight for Windows PhoneClosingOccurs when a communication object transitions into the closing state. (Inherited from CommunicationObject.)
Public eventSupported by Silverlight for Windows PhoneFaultedOccurs when a communication object transitions into the faulted state. (Inherited from CommunicationObject.)
Public eventSupported by Silverlight for Windows PhoneOpenedOccurs when a communication object transitions into the opened state. (Inherited from CommunicationObject.)
Public eventSupported by Silverlight for Windows PhoneOpeningOccurs when a communication object transitions into the opening state. (Inherited from CommunicationObject.)
Top
  NameDescription
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneIDisposable.DisposeCloses the current channel factory. (Inherited from ChannelFactory.)
Top

This generic class enables more advanced scenarios where there is a requirement to create a channel factory that can be used to create more than one type of channel.



            //Initialize channel factory with a binding and a remote endpoint address.
            BasicHttpBinding binding = new BasicHttpBinding();
            EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
            ChannelFactory<IRequestChannel> factory =
                new ChannelFactory<IRequestChannel>(binding, address);

            IRequestChannel channel = factory.CreateChannel();
            channel.Open();
            EndpointAddress epa = channel.RemoteAddress;
            Uri via = channel.Via;
            Message request = Message.CreateMessage(MessageVersion.Soap11, "hello");

            Message reply = channel.Request(request);
            Console.Out.WriteLine(reply.Headers.Action);
            reply.Close();
            channel.Close();
            factory.Close();


            //Initialize channel factory with a service configuration file.
            ChannelFactory<IRequestChannel> factory1 = new ChannelFactory<IRequestChannel>("MyEndpointConfig");

            //Initialize channel factory with a service configuration file and a remote endpoint address.
            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8000/ChannelApp");
            ChannelFactory<IRequestChannel> factory2 =
                new ChannelFactory<IRequestChannel>("MyEndpointConfig", endpointAddress);

            //Create a request channel specifying a remote endpoint address
            EndpointAddress address3 = new EndpointAddress("http://localhost:8000/ChannelApp");
            ChannelFactory<IRequestChannel> factory3 = new ChannelFactory<IRequestChannel>("MyEndpointConfig");
            factory3.CreateChannel(address3);


            //Create a request channel specifying a remote endpoint address and a transport address.
            EndpointAddress address4 = new EndpointAddress("http://localhost:8000/ChannelApp");
            Uri via4 = new Uri("http://localhost:8000/Via");
            ChannelFactory<IRequestChannel> factory4 = new ChannelFactory<IRequestChannel>("MyEndpointConfig");
            IRequestChannel channel4 = factory4.CreateChannel(address4, via4);





Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

This type is thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.