To program channel of WCF, you need to first create & configure a ChannelFactory (a class) based upon one of the endpoint exposed by the service.
Then you create a channel instance through that ChannelFactory. Once you have channel, you can make method call through that channel calling the method contract.
Once you are done with the channel, you need to Close / Abort the channel.
Let me explain, how to create a ChannelFactory based upon a particular endpoint :
This is achieved through a special class called ChannelFactory :
ChannelFactory '<'ServiceContractName'>' ObjOfChannelFactory = new ChannelFactory'<'ServiceContractName'>' ("NameOfEndpoint") ;
This allows you to create Channel, based upon specific contract type.
When you are done with construction of ChannelFactory of a particular type of ServiceContractName, you also supply target endpoint in its constructor ie, NameOfEndpoint.
Example :
ChannelFactory '<'IInvoiceService'>' cf = new ChannelFactory '<'IInvoiceService'>' ("HttpEndpoint");
Note : I have used single quote for angle bracket to avoid creating it a html tag. Don't include single quotes around the Service Contract Name while coding.
Then you create a channel instance through that ChannelFactory. Once you have channel, you can make method call through that channel calling the method contract.
Once you are done with the channel, you need to Close / Abort the channel.
Let me explain, how to create a ChannelFactory based upon a particular endpoint :
This is achieved through a special class called ChannelFactory :
ChannelFactory '<'ServiceContractName'>' ObjOfChannelFactory = new ChannelFactory'<'ServiceContractName'>' ("NameOfEndpoint") ;
This allows you to create Channel, based upon specific contract type.
When you are done with construction of ChannelFactory of a particular type of ServiceContractName, you also supply target endpoint in its constructor ie, NameOfEndpoint.
Example :
ChannelFactory '<'IInvoiceService'>' cf = new ChannelFactory '<'IInvoiceService'>' ("HttpEndpoint");
Note : I have used single quote for angle bracket to avoid creating it a html tag. Don't include single quotes around the Service Contract Name while coding.
No comments:
Post a Comment