ASP.NET MVC Web应用程序程序集中是否必须存在WCF服务引用/代理? [英] ASP.NET MVC Does the WCF service reference/proxy have to exist in the web app assembly?

查看:44
本文介绍了ASP.NET MVC Web应用程序程序集中是否必须存在WCF服务引用/代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望将Web应用程序与WCF Web服务分开.我们不希望Web应用程序知道它是否正在运行任何WCF服务.因此,我们不希望在Web应用程序程序集中定义任何WCF Web服务引用.

We want our web applications separated from our WCF web services. We don't want the web app to know if it's hitting any WCF services. Therefore we don't want any WCF web service references defined in the web app assembly.

我想做的是创建一个单独的WCF包装程序集,该程序集将包含WCF服务参考和 app.config 文件中的必要配置.WCF包装器中的方法将从Web应用程序中调用.当我在Web App程序集中创建WCF服务参考和配置时,它可以正常工作.当我将WCF Web参考和配置文件放入WCF包装程序程序集时,它抱怨找不到端点.看起来好像没有在包装程序集中找到 app.config 文件.

What I'm trying to do is create a separate WCF wrapper assembly that would contain the WCF service reference and the necessary configuration in the app.config file. Method in the WCF wrapper would be called from the Web app. When I create the WCF service reference and configuration in the Web App assembly it works fine. When I put the WCF web reference and config file in WCF wrapper assembly it complains about not finding the endpoint. It doesn't look like it's finding the app.config file in the wrapper assembly.

因此,总而言之,我想要一个如下的结构:

So in summary I want a structure as follows:

Web app --> WCF wrapper (with WCF service references and config) --> BAL layer --> etc

配置文件(如果在Web应用程序程序集中,则为web.config;如果在WCF包装程序程序集中,则为app.config):

Config file (web.config if in web app assembly, app.config if in WCF wrapper assembly):

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IEmailValidator" closeTimeout="00:01:00"
         openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
         allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
         maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
         messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
         useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
           maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
             realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8080/" binding="basicHttpBinding"
       bindingConfiguration="BasicHttpBinding_IEmailValidator" contract="EmailProxy.IEmailValidator"
       name="BasicHttpBinding_IEmailValidator" />
    </client>
  </system.serviceModel>

我是否必须在Web应用程序程序集中创建WCF服务引用,还是可以在WCF包装程序中创建它?

Do I have to create the WCF service references in the web app assembly or can I do it in the WCF wrapper?

错误消息:

找不到引用合同的默认端点元素ServiceModel客户端配置中的"EmailProxy.IEmailValidator"部分.这可能是因为找不到以下配置文件您的应用程序,或者因为没有与之匹配的终结点元素合同可以在client元素中找到.

Could not find default endpoint element that references contract 'EmailProxy.IEmailValidator' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

推荐答案

这可以追溯到一个古老的事实,即.NET配置系统不支持类库的配置文件-它期望类库的配置为在使用类库的主机应用程序中-例如在您的Web应用程序中.

This goes back to the old truth that the .NET configuration system doesn't support config files for class libraries - it expects the config for a class library to be in the host application that uses the class library - e.g. in your web application.

这实际上不是WCF问题-这是.NET团队做出的一般.NET设计决策.类库在解决方案中可能有一个 app.config 文件,甚至可能被编译成一个 myclasslibrary.dll.config -但该文件不是.NET配置系统检查并解析.

It's really not a WCF problem - it's a general .NET design decision that the .NET team made. A class library might have an app.config file in the solution, and that might even be compiled into a myclasslibrary.dll.config - but that file is not inspected and parsed by the .NET configuration system.

因此,在您的情况下,您的Web应用程序找不到配置,因此无法配置任何端点,这就是失败的原因.

Therefore, in your case, your web app cannot find the config and thus cannot configure any endpoints and that's why it fails.

您基本上有三个主要选择:

You basically have three major options:

  • 遵守此限制,并将您的WCF配置放入Web应用程序的 web.config
  • 找到一种替代方法来配置WCF服务库,例如来自其他来源,例如数据库
  • 投入大量精力使您的WCF服务库实际调查并获取类库的单独配置文件

这篇关于ASP.NET MVC Web应用程序程序集中是否必须存在WCF服务引用/代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆