kpollock
kpollock

Reputation: 3989

Dynamic Webservice reference from Class Library used in Winforms app (c#)

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...]

Upvotes: 2

Views: 2928

Answers (3)

John Saunders
John Saunders

Reputation: 161783

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.

Upvotes: 0

Justin Niessner
Justin Niessner

Reputation: 245429

Set the URL directly in your code.

YourServiceProxy service = new YourServiceProxy();
service.Url = ConfigurationManager.AppSettings["YourURLKey"];

Upvotes: 1

Steven
Steven

Reputation: 3928

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.

Upvotes: 0

Related Questions