2

I am in a situation where I need to develop a WCF Client which will have different EndPoint URI but other settings would remain same. I would get the EndPoint URI from the user.

So I wanted to know if I consume the WCF service using ChannelFactory, then do I need to have app.config file which would contain the WCF Client side configuration with only one endpoint and the address attribute would be blank (which I would get as input from the user) Or do I need to go for programmatically consuming the service.

shyam_baidya
  • 119
  • 2
  • 9

1 Answers1

1

Leave the endpoint blank in config file. In your code add a method like the one below that takes endpointAddress as a parameter which can come from the user. Use this method to create the channelfactory that you will eventually use to create proxy

private ChannelFactory<IService1> GetChannelFactory(string endpointAddress)
{    
    // create a binding that will be common
    BasicHttpBinding myBinding = new BasicHttpBinding();
    //get your uri from the user
    EndpointAddress myEndpoint = new EndpointAddress(endpointAddress);
    ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint);
    return myChannelFactory;   
}
Dhawalk
  • 1,257
  • 13
  • 28
  • Thanks for the response. Is there any dependency on the client configuration while creating proxies with ChannelFactory because I think with the above method the proxies with be created successfully even if I don't have any configuration in .config file. Correct me if I am wrong. – shyam_baidya Apr 01 '14 at 14:14
  • You might have to test that out. As I don't know that at the top of my head – Dhawalk Apr 01 '14 at 14:24