简体   繁体   English

Asp.Net与WCF服务配置文件问题

[英]Asp.Net with WCF service configuration file issue

I have a ASP.Net Web Forms application (project 1), an Entity Framework data access library (project 2) and a WCF service library (project 3). 我有一个ASP.Net Web窗体应用程序(项目1),实体框架数据访问库(项目2)和WCF服务库(项目3)。 The Asp.Net project has an *svc file that redirects calls to the corresponding WCF service in project 3. I am debugging locally using VS 2012 (+ its integrated server) and thus NO IIS is used. Asp.Net项目有一个* svc文件,该文件将调用重定向到项目3中的相应WCF服务。我正在使用VS 2012(及其集成服务器) 在本地进行调试,因此没有使用IIS。
I am encountering the following problem: if I use a page inside project 1 to get some data from the EF database, everything works fine, but when I use a remote WCF client to call the same method, if fails. 我遇到以下问题:如果我使用项目1内的页面从EF数据库中获取一些数据,则一切正常,但是当我使用远程WCF客户端调用相同的方法时,如果失败。 The error says that the connection string for the database couldn't be found. 该错误表明找不到数据库的连接字符串。 Upon investigating, I figured out that the if I call the query from the ASP project, the connection string located in Web.config file of project 1 is correctly used. 经过调查,我发现如果从ASP项目中调用查询,则正确使用了位于项目1的Web.config文件中的连接字符串。 However, if I call the query over the WCF service, the App.config of the service library is used (which of course doesn't contain any connection strings). 但是,如果我通过WCF服务调用查询,则会使用服务库的App.config(当然,其中不包含任何连接字符串)。
Up until now I thought that .NET does NOT support fragmented configuration files for DLLs (this is the reason why you have to copy over the endpoint/service configuration elements from the service App.config to the ASp.Net Web.config file). 到目前为止,我认为.NET不支持DLL的分段配置文件(这就是为什么您必须将终结点/服务配置元素从服务App.config复制到ASp.Net Web.config文件的原因)。
So does anybody know how I can get my service to use the Web.config instead it's very own App.Config, which it shouldn't use anyways? 那么,有谁知道我如何让我的服务使用Web.config而不是它自己的App.Config,无论如何都不应该使用它?

Edit : added code for *svc file and service interface + service implementation 编辑 :为* svc文件和服务接口+服务实现添加了代码

SimulatorWcfServices.svc (project 1: the main ASP.Net Web Application): SimulatorWcfServices.svc(项目1:主要的ASP.Net Web应用程序):

<%@ ServiceHost Language="C#" Debug="true" Service="Blub.SimulatorWcfServices.DataExchangeService" %>

IDataExchangeService.cs (project 3: the SimulatorWcfServices service library) IDataExchangeService.cs(项目3:SimulatorWcfServices服务库)

  [ServiceContract]
    public interface IDataExchangeService
    {
        [OperationContract]
        IDictionary<string,string> GetData();
    }

DataExchangeService.cs (project 3: the SimulatorWcfServices service library) DataExchangeService.cs(项目3:SimulatorWcfServices服务库)

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DataExchangeService : IDataExchangeService
    {
        public IDictionary<string, string> GetData()
        {
            return new DataAccessImplementation.DataDAO().GetAllData(); //call to project 2
        }
    }

I solved the issue by switching my webserver used for debugging from "Local IIS Webserver" to "Visual Studio Development Server" (Project --> Properties --> Web --> Server). 我通过将用于调试的Web服务器从“本地IIS Web服务器”切换为“ Visual Studio开发服务器”(项目->属性-> Web->服务器)解决了该问题。 So basically I downgraded the used server. 所以基本上我降级了二手服务器。 Now its uses the correct Config file and the assemblies seem to be loaded in correct order and not only partially. 现在,它使用正确的配置文件,并且程序集似乎以正确的顺序加载,而不仅仅是部分加载。

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

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