views:

944

answers:

4

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.

+2  A: 

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.

apathetic
Ahh, I didn't even notice that the generated classes were partial. That's awesome. Thanks for pointing that out!
Elijah Manor
A: 

Ahh, instead of creating another partial class with an overloaded constructor passing in the Url, the following additional parameters to the wsdl.exe will solve my problem...

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

If the web.config has a BaseSoapUrl appSetting, then it will use that to replace the http://MyServer/ sub string from the MyProxy.cs. If the appSetting is not present, then it will just use the path provided in the wsdl.exe (example: {BaseSoapUrl}/WebService1.asmx when using the appSetting or http://MyServer/WebService1.asmx when not using the appSetting).

A thanks goes out to Rick Kierner for pointing me in the right direction.

Elijah Manor
+1  A: 

To suplement Elijah's own answer, here's the email answer I gave him.

I had to blog it because the XML didn't paste well into this text box: http://www.rickdoes.net/blog/archive/2008/09/29/wsdl-shared-types-and-configuration.aspx

Rick Kierner
The link is dead
Zaffiro
Apologies: http://www.rickdoes.net/post/2008/09/29/WSDL-Shared-Types-and-configuration.aspx
Rick Kierner
A: 

If the web.config has a BaseSoapUrl...

This is confusing to me. I am executing the following commandline:

wsdl.exe /parameters:WsdlParamFile.xml

how is wsdl.exe is going to read my service's web.config on my local box? (web.config is a forbidden resource.)

In both of Elijah's and Rick's posts, the webservices are all under the same project. E.g. http://MyServer/WebService1.asmx and http://MyServer/WebService2.asmx.

How do I make this work if my services are in separate projects? E.g. http://MyServer/WebService1/WebService1.asmx http://MyServer/WebService2/WebService2.asmx

Thanks, An

An Phu