[英]Calling WCF service from class library: App.Config vs Web.Config?
From an existing WebApplication
I use to make calls to WCF services. 我使用现有的
WebApplication
来调用WCF服务。 Proxies for these services was created using Add Service Reference menu. 这些服务的代理是使用“添加服务参考”菜单创建的。 Thus generating >> Web.config in this project.
因此在此项目中生成>> Web.config。
I have added another class library project
to the solution. 我已经在解决方案中添加了另一个
class library project
。 This project also adds reference to the service. 该项目还添加了对该服务的引用。 Thus generating >> App.Config file in this project.
从而在此项目中生成>> App.Config文件。
I understand, in an N-Tier application, we should have common gateway to the service. 我了解,在N层应用程序中,我们应该具有通往该服务的通用网关。 Just out of curiosity I would like to know -
出于好奇,我想知道-
For WCF calls originated in WebApp, propagated to class library which config file (App/Web) would be referred for locating client endpoint configurations ?
对于源自WebApp的WCF调用,传播到类库中,将使用哪个配置文件(App / Web)来定位客户端终结点配置?
The web.config
file will be used for locating the service. web.config
文件将用于查找服务。
The reason is because in this case, the app domain belongs to the web app, not the class library, and the default config file for this app domain is the web.config
. 原因是因为在这种情况下,应用程序域属于Web应用程序,而不是类库,并且该应用程序域的默认配置文件是
web.config
。
@musefan is correct. @musefan是正确的。 It is the web.config that is used.
使用的是web.config。
If you want to, you can split some confuguration sections into seperate files and reference them from the main web.config. 如果需要,可以将一些配置部分分成单独的文件,并从主web.config中引用它们。 You might want to do this so you can maintain the WCF client and server config in a single place to ensure they are consistent.
您可能需要这样做,以便可以将WCF客户端和服务器配置维护在一个位置,以确保它们一致。
foe example, if you want to seperate out the <client>
section, you would do this: 例如,如果要分隔
<client>
部分,则可以这样做:
<client configSource="client.xml" />
Where client.xml is a file containing the relevant client config information. 其中client.xml是包含相关客户端配置信息的文件。
This blog post tells you how to do it in a bit more detail. 这篇博客文章告诉您如何做的更多细节。
http://blog.andreloker.de/post/2008/06/keep-your-config-clean-with-external-config-files.aspx http://blog.andreloker.de/post/2008/06/keep-your-config-clean-with-external-config-files.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.