C# – Defaulting to different URLs when Generating Web Service Proxy with WSDL.exe

asp.netcweb serviceswsdl

I have numerous Web Services in my project that share types.

For simplicity I will demonstrate with two Web Services.

WebService1 at http://MyServer/WebService.asmx
webService2 at http://MyServer/WebService.asmx

When I generate the proxy for these two services I use:

wsdl /sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx
/appsettingurlkey:WebServiceUrl /namespace:MyNamespace /out:MyProxy.cs

The problem is that the appsettingurlkey is the same for each Web Service
in the proxy file. I want to be able to specify multiple
appsettingurlkey parameters. How is this accomplished? I figure
since the /sharetypes parameter became available, there should be a
solution for specifying the appsettingurlkey specifically for each
Web Service identified.

If this is not possible with the wsdl.exe, what would you propose I do? I would rather not update the generated code that wsdl.exe outputs and I don't want to go through my whole application passing in the Url to each instance of the Web Services.

Best Answer

The proxy classes generated are partial classes, so my solution would be to add your own constructor in a different (non-generated) code file, which explicitly reads a different setting for each proxy.