views:

1173

answers:

3

Ok - pretty basic scenario, been there before, seemed all so simple - but can't recall enough to work out what's different about the setup at this particular existing codebase.

Winforms App calls Dll which calls Web Service. Reference in the Dll to the Web Service is dynamic. How do I get the URI for the Web Service into a Winforms app.config so I can easily change it for test, dev, live etc.

[Oh just to make it interesting, though I can't see it mattering, the proxy for the web service needs to NOT be regenerated as we have customised it...]

A: 

Can you configure the web service URI dynamically in code? That way you can easily modify the service to point to the desired location.

You can set the Url property of the webservice in code to point to the URI and use Proxy to set the proxy to your custom proxy.

Steven
That's my usual way - but I don't think the existing dll code is not set up that way. Suppose I'd just better rewrite some of it..
kpollock
+1  A: 

Set the URL directly in your code.

YourServiceProxy service = new YourServiceProxy();
service.Url = ConfigurationManager.AppSettings["YourURLKey"];
Justin Niessner
yeah - I'm resigned to rewriting some of the existing code
kpollock
A: 

What's wrong with just copying the URL from the app.config of the library into the app.config of the Windows Forms application?

Also, I'll suggest strongly that you do not modify generated code, ever. You can make many customizations of the proxy by using partial classes. See Ways to Customize your ASMX Client Proxy.

John Saunders
customisation is not my doing - for what it's worth I agree!
kpollock
Ok, though perhaps you can un-do it...
John Saunders