简体   繁体   English

从类库中调用WCF服务:App.Config与Web.Config?

[英]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.

相关问题 WCF:在我的app.config / web.config中使用我的“自定义”ServiceHost来获取我的wcf服务? - WCF: Using my “custom” ServiceHost in my app.config/web.config for my wcf service? WCF客户端实现,有办法将服务和端点详细信息保留在类库app.config中,而不是在ASP.NET MVC应用程序中保留在web.config中 - WCF Client Implementation, is there way to keep services and end-point detail in class library app.config rather then web.config for ASP.NET MVC app App.config或Web.config - App.config or Web.config 从 .NET 中的 app.config 或 web.config 读取设置 - Reading settings from app.config or web.config in .NET WCF服务app.config - WCF Service app.config 从Web项目访问类库中的app.config文件 - Access app.config file in class library from web project Windows Service托管WCF库:app.config connectionStrings - Windows Service hosting WCF Library: app.config connectionStrings app.config或web.config中的配置与WCF中的代码之间的关系 - relationship between configuration in app.config or web.config and code in WCF app.config用于类库 - app.config for a class library 从具有web.config的服务调用DLL时如何读取DLL自己的app.config? - How to read DLL's own app.config when it's called from a service that has a web.config?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM