简体   繁体   English

WEBAPI客户端服务器绑定信息

[英]WEBAPI client server binding information

If you're developing a WebAPI client where would you store information about the server you're connecting to, assuming that the information will be different in dev, staging and production. 如果您正在开发WebAPI客户端,那么您将在其中存储有关要连接的服务器的信息,并假定该信息在开发,登台和生产中会有所不同。

Is it possible to have profiles defined for each deployment environment similar to web application deployment profiles. 是否可以为每个部署环境定义与Web应用程序部署配置文件类似的配置文件。

In my case, we're building a library that consumes a WEBAPI service that could be deployed either locally, on an intranet or on the cloud 就我而言,我们正在构建一个使用WEBAPI服务的库,该服务可以在本地,Intranet或云上部署

The only thing that i did so far to lessen the problem is to define the server binding information (server address/port) in an App.config . 到目前为止,我为减轻问题所做的唯一一件事就是在App.config定义服务器绑定信息(服务器地址/端口)。 When i build my library i have a mylib.dll and mylib.dll.config that i can customize. 构建我的库时,我有一个可以自定义的mylib.dllmylib.dll.config

I would have preferred to set the right information at deployment time. 我希望在部署时设置正确的信息。

Any ideas from folks who run into similar issues 遇到类似问题的人们的任何想法

-ken

If you are using Visual Studio for deployment, have a look Web.config Transformation Syntax for Web Project Deployment Using Visual Studio In VS 2012, right-click your config file and select Add Transform, as simple as that. 如果要使用Visual Studio进行部署,请查看使用Visual Studio进行Web项目部署的Web.config转换语法。在VS 2012中,右键单击配置文件,然后选择“ 添加转换”,就这么简单。 This will add Web.Debug.config and Web.Release.config (assuming you have standard build configuration) which will be used to apply transformations to Web.config in compile time. 这将添加Web.Debug.config和Web.Release.config(假设您具有标准的构建配置),这将用于在编译时将转换应用于Web.config。

The only disadvantage is that Solution configuration now also points to environment which may be annoying and breaks SRP. 唯一的缺点是解决方案配置现在还指向可能令人烦恼并破坏SRP的环境。

The best approach I know so far is to use Octopus which supports config file transformations in deployment time. 到目前为止,我所知道的最好方法是使用Octopus,它在部署期间支持配置文件转换 This way solution configuration does what it should and nothing else. 通过这种方式,解决方案配置可以完成应有的工作,而无需执行其他任何操作。

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

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