Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change service reference URL in code

I'm working in a Windows Phone 8 project and in order to use some webservices I added a service reference with a specific URL.

My problem is the URL because it changes fom time to time so I need to let the user insert the new URL from some menu when the app is running.

I know how to change it in Visual Studio but now I need to change it in code when the app is running..so my question is: how do I change the URL in code?

I have done some search and the file "app.config" seems to do the job but I don't have any "app.config" in my project and from what I saw Windows Phone projects don't use such file.

like image 318
sparcopt Avatar asked Jul 22 '13 15:07

sparcopt


People also ask

How do I change the service reference URL in C#?

No need to write any code. Just change the URL in app. config and it will work.

How do you update a service reference?

To update a service reference In Solution Explorer, right-click the service reference and then click Update Service Reference. A progress dialog box displays while the reference is updated from its original location, and the service client is regenerated to reflect any changes in the metadata.

How do I change a web service?

Go to transaction SE80 where you will find EDIT OBJECT button click on that then you will find Object Selection box in that box select the tab of Enterprise Services in that tab select the first Radio button of Server Definition in that Textbox write the name of web-service and then press the Delete button .

How do I change my Asmx service reference?

In Solution Explorer, open your project's App_WebReferences folder and click the node for the Web reference you want to update. Right-click the reference and click Update Web Reference. The new files for the XML Web service are downloaded to your project.

How to map class code behind a web service URL?

This setting is by default set to Static. To make the URL in the Reference.cs map class code behind look for the web service URL in your web.config file, we need to change this setting to Dynamic: Doing this in VS.NET does two things for you.

Why can't I change service reference configuration during the runtime?

This means that it cannot be changed (at least not without using reflection) during the runtime. Basically you are stuck with service reference configuration until your application is restarted. For web applications this is not a big issue since web application is restarted by itself on every change of web.config.

How do I change the URL behavior of a proxy reference?

All this will be done by changing one property setting on the proxy reference. If you look at the web reference properties (below): you can see that there is a configuration setting called 'URL Behavior'.

What happens if I change the WSDL url during the runtime?

In case you change the WSDL url during the runtime and initiate service request by entering ZIP code value, you will not get any exception, simply because your changes are not picked up from the config. They are initially loaded on start and they remain loaded on the AppDomain level regardless of the changes in app.config.


1 Answers

Simply change the endpoint address, e.g.

clientProxy.Endpoint.Address = new EndpointAddress(yourUri);
like image 109
George Johnston Avatar answered Oct 11 '22 17:10

George Johnston