Alex Rivera | Logout

Create WCF service client with specified address without specifying configuration name

Asked 2011-09-29T15:27:32.753
13

Is there a way to create an instance of a WCF service client in C# with a specified endpoint address without specifying a configuration name?

By default, clients have these constructors:

    public ServiceClient() 
    public ServiceClient(string endpointConfigurationName)
    public ServiceClient(string endpointConfigurationName, string remoteAddress)

Obviously, there is a default configuration, because of the first constructor. What I want is to only specify the 2nd parameter of the final constructor. Right now, I'm struggling through reading the configuration elements of using ConfigurationManager to figure it out, but it seems horribly cumbersome. Is there a cleaner way?

Edit
Report

1 Answer

13

I prefer not to use the endpoint configuration in the .config file. I normally do something like this:

        BasicHttpBinding basicbinding = new BasicHttpBinding();
        basicbinding.SendTimeout = TIMEOUT;
        basicbinding.OpenTimeout = TIMEOUT;
        ServiceClient client = new ServiceClient(basicbinding, new EndpointAddress(new Uri("http://xxxxx")));
answered 2011-09-29T15:45:11.777

Your Answer