Reputation: 119
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.
Upvotes: 2
Views: 363
Reputation: 1269
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;
}
Upvotes: 1