Change service reference URL in code
Asked Answered
P

1

19

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.

Protecting answered 22/7, 2013 at 15:36 Comment(1)
possible duplicate of dynamically switch WCF web service reference URL path through config fileOlomouc
F
41

Simply change the endpoint address, e.g.

clientProxy.Endpoint.Address = new EndpointAddress(yourUri);
Frontwards answered 22/7, 2013 at 15:39 Comment(4)
The constructor for the clientProxy class can also take a URL which will basically do the same thing.Olomouc
Actually if you want to pass the value through constructor like Cory suggested, you should make sure you pass in the right params as there are several overloads of the constructor.Fredericksburg
If I do this, I encounter a contract mismatch exception, since the URL used when creating the hard coded service reference differs from the URL used in the constructor for the client. It seems like this method does not truly change the endpoint address? I may be missing something.Diffuse
I would really hope that a constructor would take that in. It's something I get to do every few years and always have to look it up here... Thanks for the answer.Rubi

© 2022 - 2024 — McMap. All rights reserved.