简体   繁体   English

具有DEV,QA和PROD版本的WCF服务

[英]WCF service with a version for DEV, QA and PROD

First off, I did look on google and stackoverflow, but nothing seem to really meet my desires. 首先,我确实看过google和stackoverflow,但似乎没有什么能真正满足我的需求。

That said. 那就是。 I am using an MVC application (It could just as well be a Web Forms app) that I inherited from a previous developer(s). 我正在使用从以前的开发人员那里继承的MVC应用程序(也可能是Web Forms应用程序)。 The current Service References point at production servers and I would like to simply point also at local dev servers. 当前的服务参考指向生产服务器,而我也想简单地指向本地开发服务器。 Ideally I would like to not edit the web.config file for changing from dev to prod (especially if it is for several places etc..) 理想情况下,我不想编辑从dev到prod的web.config文件(尤其是在多个地方等)。

Thus, perhaps there is a "best practice" for adding extra web references and being able to quickly "swap and test" the DEV references to PROD references with very little configuration changes. 因此,也许有“最佳实践”用于添加额外的Web引用,并且能够通过很少的配置更改就可以快速地“交换和测试” DEV引用到PROD引用。

Perhaps a design pattern, or an appconfig setting to facilitate this process? 也许是设计模式或appconfig设置来简化此过程? It certainly would be ideal to keep it loosely coupled with constructor injection of the service references. 使它与服务引用的构造函数注入保持松散耦合肯定是理想的。 Any thoughts on how to best implement this? 关于如何最好地实现这一点的任何想法?

Another option would be to add multiple endpoint configurations for the same service that point to different addresses. 另一种选择是为同一服务添加指向不同地址的多个端点配置。 Then when you create a new instance of your service client you pass the name of then endpoint configuration. 然后,当您创建服务客户端的新实例时,您将传递端点配置的名称。

ContractServiceContractClient client = 
new ContractServiceContractClient("DEV_Endpoint");

or 要么

ContractServiceContractClient client = 
new ContractServiceContractClient("PROD_Endpoint");

And in your ServiceReference config 并在您的ServiceReference配置中

<endpoint address="http://localhost:7821/ContractService.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_ContractService"
          contract="ContractServiceReference.IContractService" 
          name="DEV_Endpoint" />

or 要么

<endpoint address="http://service.apps.com/ContractService.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_ContractService"
          contract="ContractServiceReference.IContractService" 
          name="PROD_Endpoint" />

Then if you just create a global static string or put something in your app.config that contains the name of the endpoint configuration you want to use, then you just have to change it in that one spot and it will update across the application. 然后,如果您仅创建一个全局静态字符串或在您的app.config中放入包含您要使用的端点配置名称的内容,则只需在该位置进行更改,它将在整个应用程序中更新。

The only catch here is that you can't create an instance of your service client without passing which endpoint configuration you want to use if you have more than one endpoint configuration for the same contract. 这里唯一要注意的是,如果同一合约具有多个端点配置,那么您将无法创建服务客户端的实例,而无需传递要使用的端点配置。

what I usually do is to have all settings in the database, and we have different database connection strings (machines are different) for each environment. 我通常要做的是在数据库中拥有所有设置,并且每种环境下我们都有不同的数据库连接字符串(机器不同)。

in the app/web.config we simply change 1 key specifying to which environment we are pointing then everything else comes from the settings table in the database which contains different values per environment. 在app / web.config中,我们只需更改1键即可指定要指向的环境,然后其他所有操作都来自数据库的设置表,该表在每个环境中包含不同的值。 For service references the checked-in code always and only points to localhost and at runtime the url is assigned from the settings retrieved from the db. 对于服务引用,签入代码始终且仅指向localhost,在运行时,将从数据库检索的设置中分配URL。

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

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