制作一个Web服务引用configuarble - ASP.NET? [英] Making a web service reference configuarble - ASP.NET?

查看:140
本文介绍了制作一个Web服务引用configuarble - ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们继承了一些code,使得使用Web服务从第三方外部服务器上。目前,所有的参考文献中的项目直接并因此编译到该位置和这样做。这个问题我们是有具有不同的URL的Web服务测试和生产服务器。

We inherited some code that makes use of a web service on an external server from a third party. Currently all the references are done in the project directly and thus compiled to that location and such. This issue we have is that there is a test and production server for the web service with different URLs.

有一个简单的手段,使网站更参考动态,以便它可以在一个web.config中定义,而不是需要改变的实际来源和重新编译到服务器之间切换?

Is there a simple means to make the web reference more dynamic so that it can be defined in a web.config and not require changing the actual source and recompiling to switch between servers?

推荐答案

您可以把在 web.config中的的appSettings 部分链接文件:

You could put the url in the appSettings section of the web.config file:

<appSettings>
    <add key="wsUrl" value="http://example.com/staging.asmx" />
</appSettings>

然后读值和web服务代理类的构造函数,并将其分配给<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.services.protocols.webclientprotocol.url.aspx\"相对=nofollow>网址属性:

public SomeProxy()
{
    Url = ConfigurationManager.AppSettings["wsUrl"];
}

这篇关于制作一个Web服务引用configuarble - ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆