I remember with ASMX there was an easy solution:
 MyAsmxServiceClient serviceClient = 
     new MyAsmxServiceClient("http://myServiceLocation/myService.asmx");
How can achieve the same with WCF?
That's usually done in the app.config/web.config:
<system.serviceModel>
    <client>
        <endpoint
            address="http://myServiceLocation/myService.asmx"
            binding="basicHttpBinding"
            contract="IMyServiceContract" />
    </client>
</system.serviceModel>
or you could also do it programatically if you prefer.
Normally when you generate the client side proxy using the svcutil.exe it will also create a sample output.config file containing all you need to setup the configuration.
UPDATE:
You could also provide names to your endpoints:
<system.serviceModel>
    <client>
        <endpoint
            name="foo"
            address="http://foo.com/myService.asmx"
            binding="basicHttpBinding"
            contract="IMyServiceContract" />
        <endpoint
            name="bar"
            address="http://bar.com/myService.asmx"
            binding="basicHttpBinding"
            contract="IMyServiceContract" />
    </client>
</system.serviceModel>
and then:
using (var client = new MyClientProxy("foo"))
{
    var result = client.SomeMethod();
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With