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.
No need to write any code. Just change the URL in app. config and it will work.
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.
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 .
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.
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.
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.
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'.
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.
Simply change the endpoint address, e.g.
clientProxy.Endpoint.Address = new EndpointAddress(yourUri);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With