C# 在代码中更改服务引用 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17791690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:29:33  来源:igfitidea点击:

Change service reference URL in code

c#urlwindows-phone-8service-referencevisual-studio-2013

提问by sparcopt

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.

我在一个 Windows Phone 8 项目中工作,为了使用一些网络服务,我添加了一个带有特定 URL的服务引用。

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

我的问题是 URL,因为它不时更改,所以我需要让用户在应用程序运行时从某个菜单插入新 URL。

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?

我知道如何在 Visual Studio 中更改它,但现在我需要在应用程序运行时在代码中更改它..所以我的问题是:如何更改代码中的 URL?

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.

我已经做了一些搜索,文件“app.config”似乎可以完成这项工作,但我的项目中没有任何“app.config”,并且从我看到的 Windows Phone 项目不使用这样的文件。

采纳答案by George Johnston

Simply change the endpoint address, e.g.

只需更改端点地址,例如

clientProxy.Endpoint.Address = new EndpointAddress(yourUri);