简体   繁体   English

在不同环境中使用Web服务

[英]Using web services in different environments

We have a series of web services that live in different environments (dev/qa/staging/production) that are accessed from a web application, a web site, and other services. 我们提供了一系列Web服务,它们生活在不同的环境(dev / qa / staging / production)中,可以从Web应用程序,网站和其他服务中进行访问。 There are a few different service areas as well. 也有一些不同的服务领域。 So for production, we have services on four different boxes. 因此,对于生产,我们在四个不同的盒子上提供服务。

We conquered the db connection string issue by checking the hostname in global.asax and setting some application wide settings based on that hostname. 通过检查global.asax中的主机名并基于该主机名设置一些应用程序范围的设置,我们解决了数据库连接字符串问题。 There is a config.xml that is in source control that list the various hostnames and what settings they should get. 源代码管理中有一个config.xml,其中列出了各种主机名及其应获取的设置。

However, we haven't found an elegant solution for web services. 但是,我们尚未找到针对Web服务的优雅解决方案。 What we have done so far is add references to all the environments to the projects and add several using statements to the files that use the services. 到目前为止,我们所做的就是将对所有环境的引用添加到项目中,并在使用服务的文件中添加一些using语句。 When we checkout the project, we uncomment the appropriate using statement for the environment we're in. 当我们签出项目时,我们会取消注释所处环境的适当using语句。

It looks something like this: 看起来像这样:

// Development
// using com.tracking-services.dev
// using com.upload-services.dev

// QA
// using com.tracking-services.qa
// using com.upload-services.qa

// Production
// using com.tracking-services.www
// using com.upload-services.www

Obviously as we use web services more and more this technique will get more and more burdensome. 显然,随着我们越来越多地使用Web服务,此技术将变得越来越繁重。

I have considered putting the namespaces into web.config.dev, web.config.qa, etc and swapping them out on application start in global.asax. 我考虑过将名称空间放入web.config.dev,web.config.qa等中,并在应用程序中从global.asax开始将其交换出来。 I don't think that will work because by the time global.asax is run the compilation is already done and the web.config changes won't have much effect. 我认为这行不通,因为在运行global.asax时,编译已经完成,并且web.config更改不会产生太大影响。

Since the "best practices" include using web services for data access, I'm hoping this is not a unique problem and someone has already come up with a solution. 由于“最佳实践”包括使用Web服务进行数据访问,因此我希望这不是一个唯一的问题,并且有人已经提出了解决方案。

Or are we going about this whole thing wrong? 还是我们将整个事情搞错了?

Edit: These are asmx web services. 编辑:这些是asmx Web服务。 There is no url referenced in the web.config that I can find. 我找不到在web.config中引用的URL。

Make one reference and use configuration to switch the target urls as appropriate. 进行参考并使用配置来适当地切换目标URL。 No reason to have separate proxies at all. 完全没有理由使用单独的代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM