'How to generate web service client from WSDL (like a pro), when address is changing frequently?

I have to consume some service on ESB which has addresses:

  1. for dev env: http://esbdev.com:11111/ws/ir.channel.aaa.pub.ws:ConsumeMeV1
  2. for test env: https://esbtest.com:22222/ws/ir.channel.aaa.ws:DoAmazingCalc

Functionality is the same.

Can I somehow have only one common code (to rule them all) in c# generated from WSDL and manipulate to which env I’m connecting by some config? And can i switch freely between http on dev and https on test environment?

Now I’m calling it on dev like:

using (ConsumeMeV1_PortTypeClient client = new ConsumeMeV1_PortTypeClient(this.EsbEndpointBinding, this.EsbEndpointAddress))

But there is dev name hardcoded - how should i map ConsumeMeV1 to DoAmazingCalc on test?

On test I'm calling it like:

using (DoAmazingCalc_PortTypeClient client = new DoAmazingCalc_PortTypeClient(this.EsbEndpointBinding, this.EsbEndpointAddress))

Can I generate common clases like:

using (BestServiceNameClient client = new BestServiceNameClient(this.EsbEndpointBinding, this.EsbEndpointAddress))

The best option for me is to get endpoint/names config from database and inject to clinet class - but how?



Solution 1:[1]

Ok, I know where the minuses come from.

No part of the address matters as long as the functionality underneath it does not change. So both generated classes will allow you to use them with each of the given addresses. I note that these obvious things are like that only when you know about it, so I'm sorry that no one even wrote a word about it.

However, when it comes to https, it depends on the BasicHttpBinding.Security.Mode settings. You can set Transport for https and TransportCredentialOnly for http. The corresponding value can be saved and retrieved from the database or other configuration together with the user and password.

I use the above with the setting: BasicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 skk