简体   繁体   English

如何在生产中配置WCF客户端?

[英]How do you configure a WCF client in production?

There are numerous resources available on WCF and configuration (both programmatic and via app.config). WCF和配置上有许多可用的资源(程序化和通过app.config)。 However, I have not seen a good resource on practical management of this configuration, particularly in a production environment. 但是,我没有看到关于此配置的实际管理的良好资源,特别是在生产环境中。

WCF is powerful in that the framework allows configuration via the app.config file so that you can tweak various settings without having to recompile code. WCF功能强大,因为框架允许通过app.config文件进行配置,因此您可以调整各种设置,而无需重新编译代码。

When installing a WCF client, how do you easily configure the client to point to the right server? 安装WCF客户端时,如何轻松配置客户端以指向正确的服务器? This is probably the most common thing I can think of to configure after installing. 这可能是我在安装后可以考虑配置的最常见的事情。 For some context, suppose I ship a product which has a server component and a client component. 对于某些上下文,假设我发运的产品包含服务器组件和客户端组件。 Customers can install both wherever. 客户可以在任何地方安装。 While an xml file is powerful for post-development configuration, it is not user-friendly at all. 虽然xml文件对于开发后配置非常强大,但它根本不是用户友好的。 Given that there can be several dozen endpoints in a config file, does the admin or end user have to manually change all of them? 鉴于配置文件中可能有几十个端点,管理员或最终用户是否必须手动更改所有端点? I know I could do everything programmatically, but then I essentially am re-implementing all of the out-of-the-box plumbing. 我知道我可以通过编程方式完成所有工作,但后来我基本上正在重新实现所有开箱即用的管道。

Above question, more generalized is: how can I simplify WCF configuration via some basic UI without re-implementing what is provided by the framework? 上面的问题,更通用的是:如何通过一些基本UI简化WCF配置,而无需重新实现框架提供的内容?

If you want user friendly installation you will use some installer where you simply set some configuration values. 如果您想要用户友好的安装,您将使用一些安装程序 ,您只需设置一些配置值。 Check either installer project provided as part of Visual studio or more powerful (and much more complex) WiX . 检查作为Visual Studio的一部分提供的安装程序项目或更强大(更复杂)的WiX If you don't have installer you already chose that users are supposed to configure everything manually. 如果您没有安装程序,则您已选择用户应手动配置所有内容。

If your only problem is address of services and you plan to deploy services and clients to single LAN you can also add WS-Discovery ( available in WCF 4 ) where clients are able to find service on the network. 如果您唯一的问题是服务地址,并且您计划将服务和客户端部署到单个LAN,则还可以添加WS-Discovery( 在WCF 4中可用 ),客户端可以在该网络上查找服务。

if you like to have/make a nice UI to edit those settings, the user input from that UI will need to be saved somewhere and you will have to use it when creating your service calls on the clients or setting up your hosted services on the server. 如果您希望拥有/制作一个很好的用户界面来编辑这些设置,那么该用户界面中的用户输入需要保存在某个地方,您必须在客户端上创建服务调用或在服务器上设置托管服务时使用它。服务器。 Personally I would store in the database and will use them to configure the WCF endpoints at runtine with coded approach. 我个人会存储在数据库中,并将使用它们以编码方式配置runtine的WCF端点。

this has also some advantages, all backed up with db backup, remote connection and inspection, no risk to overwrite files on updates and so on. 这也有一些优点,所有备份都支持db备份,远程连接和检查,没有覆盖更新文件的风险等等。

If your setup/application has no database then configuration files are also ok and probably the only way, I would not save anything in the Registry anyway. 如果您的设置/应用程序没有数据库,那么配置文件也可以,这可能是唯一的方法,无论如何我都不会在注册表中保存任何内容。

You could use the settings framework to store the endpoint address. 您可以使用设置框架来存储端点地址。 You can easily read and save settings and they'll be stored in the %APPDATA% location so you don't need to worry about permissions. 您可以轻松阅读和保存设置,它们将存储在%APPDATA%位置,因此您无需担心权限。 You'd need just a small configuration UI where the user can enter the server name. 您只需要一个小配置UI,用户可以在其中输入服务器名称。 Validate that configuration by adding a simple Hello service to your server and try to reach that service in that UI. 通过向服务器添加简单的Hello服务来验证该配置,并尝试在该UI中访问该服务。 So you can give the user immediate feedback if the server address is right. 因此,如果服务器地址正确,您可以立即向用户提供反馈。

The other option is to implement a discovery protocol. 另一种选择是实现发现协议。 A related question is here . 一个相关的问题在这里

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

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