Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you change the location/endpoint of a dynamic web reference at run-time in .NET?

In a fairly standard fashion, I created a Web Reference to a SOAP service in Jira for an extension that I'm building (Jira is an issue tracker for those unfamiliar with it). Visual Studio auto-generates a .Settings file and an app.config that contains the web service URL.

Since I'm developing an extension/plugin to an ALM product we're building, the consumer of the extension will be the one who ultimately decides where this web service points to, because it will be integrated with the consumer's instance of Jira. Assume that the web service URL would be stored and pulled from a database.

How can I get the auto-generated service to use a URL from a database instead of from the generated app.config?

Note: we are using v2.0 of the framework, so WCF is not an option.

like image 525
John Rasch Avatar asked Feb 11 '10 16:02

John Rasch


People also ask

How do I change a dynamic Web service reference?

If you are fetching the URL from a database you can manually assign it to the web service proxy class URL property. This should be done before calling the web method. If you would like to use the config file, you can set the proxy classes URL behavior to dynamic. Save this answer.

How do I add a Web service reference in Visual Studio 2010?

In Solution Explorer, right-click the name of your project, and then click Add Service Reference. In the Add Service Reference dialog box, click Advanced. In the Service Reference Settings dialog box, click Add Web Reference.


2 Answers

Even in the 2.0 web service you should be able to change the "Url" property of your web service proxy to the value you desire.

like image 140
Otávio Décio Avatar answered Oct 24 '22 19:10

Otávio Décio


Use the constructor of the client that admits the uri.

like image 1
Pablo Castilla Avatar answered Oct 24 '22 18:10

Pablo Castilla