Monday, September 20, 2010

Fundamentals of Creating a WCF Client (WCF Part 6)


Fundamentals of Creating a WCF Client: Like almost all other distributed technologies, clients use proxies to access WCF services.

    Proxies can be created in one of two ways:

  1. at design time by using the svcutil.exe command line tool
  2. dynamically at runtime by using a ChannelFactory.

A ChannelFactory provides a flexible way to create proxies at runtime, by creating a factory from the address, binding details, and contract details, and then calling CreateChannel on the factory.

Creating a Client by Using a Channel Factory:


ChannelFactorycf = new ChannelFactory(new EndpointAddress("http://localhost/MyService/EndPoint1"),new BasicHttpBinding());
IMyChannel ch1=cf.CreateChannel();


To send messages you must open the channel. and after finishing you have to Close the channel.

The ChannelFactory class has a number of methods and properties that enable you to access features of the underlying channel. e.g the Credentials property:


proxy.ChannelFactory.Credentials.UserNamePassword.UserName = "Mohamed Adel Mahmoud";
proxy.ChannelFactory.Credentials.UserNamePassword.Password = “P@$$w0rd”;


  For More Info Please Visit: WCF Resources Page  

No comments:

Post a Comment

Search This Blog