应该修改什么来更改 C# 中 Web 服务的 URL?
我有一个问题,不久前我通过复制所有生成的代码(复制粘贴 .cs 内容的文本)将 Webservice 代理类添加到我的应用程序中。
它成功了!
但现在我需要更改此 Web 服务代理类使用的 URL,并且我不确定在代码中更改什么以及在哪里更改。
如果您能给我一条线索,指导我找到正确的位置,以便我可以更新网络服务的 URL,我将不胜感激。
I have one problem and it is some time ago I have added a Webservice proxy class into my application by copying all the generated code (copy paste the text of the .cs content).
And it worked!
But now I need to change the URL used by this web-service proxy class and I am not sure what and where to change in the code.
I would appreciate if you can give me a clue that can guide me to find the right place so that I can update the url of the web service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它是生成的 asmx webservice 代理,则代理类有一个属性 -
URL
。您可以在创建代理对象的位置设置
URL
属性,也可以将其硬编码到代理类中。默认情况下,生成的代理类在构造函数中包含代码,用于从应用程序设置中设置
URL
属性。If it´s a generated asmx webservice proxy the proxy class have a property -
URL
.You can set the
URL
property where you create the proxy object or you can hard code it into the proxy class.By default a generated proxy class have code in the constructor to set the
URL
property from application settings.您应该使用 web.config 更改 URL。
如果您转到添加的 Web 引用的属性,您应该会看到一个名为“'URL Behaviour'”的属性。将其值设置为“动态”并提供 URL。这将在 web.config 中创建一个条目,并且每当您更改该条目时,都会采用该 URL。
更多信息此处。
You should change the URL using web.config.
If you go to the properties of the web reference added, you should see a property named "'URL Behavior'". Set the value of that to "dynamic" and supply the URL. That would make an entry in the web.config and whenever you change that entry, that URL will be taken.
More info here.
使用 URL 属性
Use the URL property