为什么找不到我的自定义 WCF 行为扩展元素类型? [英] Why isn't my custom WCF behavior extension element type being found?

查看:24
本文介绍了为什么找不到我的自定义 WCF 行为扩展元素类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个项目的解决方案.一个项目是 ASP.NET Web 应用程序项目,一个是类库.Web 应用程序具有对类库的项目引用.这些都不是强命名的.

I have a solution that contains two projects. One project is an ASP.NET Web Application Project, and one is a class library. The web application has a project reference to the class library. Neither of these is strongly-named.

在类库中,我将其称为框架",我有一个端点行为(一个 IEndpointBehavior 实现)和一个配置元素(一个派生自 BehaviorExtensionsElement 的类).配置元素使我可以通过配置将端点行为附加到服务.

In the class library, which I'll call "Framework," I have an endpoint behavior (an IEndpointBehavior implementation) and a configuration element (a class derived from BehaviorExtensionsElement). The configuration element is so I can attach the endpoint behavior to a service via configuration.

在 Web 应用程序中,我有一个支持 AJAX 的 WCF 服务.在 web.config 中,我将 AJAX 服务配置为使用我的自定义行为.配置的 system.serviceModel 部分非常标准,如下所示:

In the web application, I have an AJAX-enabled WCF service. In web.config, I have the AJAX service configured to use my custom behavior. The system.serviceModel section of the configuration is pretty standard and looks like this:

<system.serviceModel>
 <behaviors>
  <endpointBehaviors>
   <behavior name="MyEndpointBehavior">
    <enableWebScript />
    <customEndpointBehavior />
   </behavior>
  </endpointBehaviors>
 </behaviors>
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
 <services>
 <service name="WebSite.AjaxService">
  <endpoint
           address=""
           behaviorConfiguration="MyEndpointBehavior"
           binding="webHttpBinding"
           contract="WebSite.AjaxService" />
  </service>
 </services>
 <extensions>
  <behaviorExtensions>
   <add
       name="customEndpointBehavior"
       type="Framework.MyBehaviorExtensionsElement, Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  </behaviorExtensions>
 </extensions>
</system.serviceModel>

在运行时,这完美地工作.启用 AJAX 的 WCF 服务正确使用我自定义配置的端点行为.

At runtime, this works perfectly. The AJAX enabled WCF service correctly uses my custom configured endpoint behavior.

问题是当我尝试添加新的 AJAX WCF 服务时.如果我添加 ->新建项目...并选择启用 AJAX 的 WCF 服务",我可以看到它添加了 .svc 文件和代码隐藏,但是当它更新 web.config 文件时,我收到此错误:

The problem is when I try to add a new AJAX WCF service. If I do Add -> New Item... and select "AJAX-enabled WCF Service," I can watch it add the .svc file and codebehind, but when it gets to updating the web.config file, I get this error:

配置文件不是 WCF 服务库的有效配置文件.

The configuration file is not a valid configuration file for WCF Service Library.

无法加载为扩展customEndpointBehavior"注册的类型Framework.MyBehaviorExtensionsElement, Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null".

The type 'Framework.MyBehaviorExtensionsElement, Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' registered for extension 'customEndpointBehavior' could not be loaded.

显然该配置完全有效,因为它在运行时完美运行.如果我暂时从我的行为配置中删除该元素,然后添加支持 AJAX 的 WCF 服务,一切都会顺利进行.

Obviously the configuration is entirely valid since it works perfectly at runtime. If I remove the element from my behavior configuration temporarily and then add the AJAX-enabled WCF Service, everything goes without a hitch.

不幸的是,在一个更大的项目中,我们将拥有多个具有各种配置的服务,临时删除所有自定义行为将很容易出错.虽然我意识到我可以在不使用向导的情况下手动完成所有操作,但并不是每个人都可以,而且能够按照预期使用的方式使用该产品会很好 - 向导等等.

Unfortunately, in a larger project where we will have multiple services with various configurations, removing all of the custom behaviors temporarily is going to be error prone. While I realize I could go without using the wizard and do everything manually, not everyone can, and it'd be nice to be able to just use the product as it was meant to be used - wizards and all.

为什么找不到我的自定义 WCF 行为扩展元素类型?

更新/说明:

  • 它确实在运行时有效,只是在设计时无效.
  • 当我尝试添加服务时,框架程序集位于 Web 项目的 bin 文件夹中.
  • 虽然我可以手动添加服务(无需配置"),但我需要开箱即用的项目模板才能工作 - 这就是问题的全部目标.
  • 此问题在 Visual Studio 2008 中出现.在 VS 2010 中,此问题似乎已解决.

我在 Microsoft Connect 上提交了这个问题您要么必须将自定义配置元素放在 GAC 中,要么将其放在 IDE 文件夹中.他们不会修复它,至少现在是这样.我已经发布了他们作为答案"提供的解决方法.对这个问题.

I filed this issue on Microsoft Connect and it turns out you either have to put your custom configuration element in the GAC or put it in the IDE folder. They won't be fixing it, at least for now. I've posted the workaround they provided as the "answer" to this question.

推荐答案

Per 微软在连接问题> 我为此提出了申请,这是一个已知问题,至少在当前版本中没有任何解决方案:

Per the workaround that Microsoft posted on the Connect issue I filed for this, it's a known issue and there won't be any solution for it, at least in the current release:

无法添加新的原因服务项目:添加新项目时并更新配置文件,系统将尝试加载配置文件,所以它会尝试搜索并加载程序集此配置文件中的 cusom 扩展名.只有在装配体是GACed 或位于同一路径作为 vs exe (Program FilesMicrosoftVisual Studio 9.0Common7IDE),系统可以找到.否则,将弹出错误对话框并添加一个新项目"将失败.

The reason for failing to add a new service item: When adding a new item and updating the configuration file, the system will try to load configuration file, so it will try to search and load the assembly of the cusom extension in this config file. Only in the cases that the assembly is GACed or is located in the same path as vs exe (Program FilesMicrosoft Visual Studio 9.0Common7IDE), the system can find it. Otherwise, the error dialog will pop up and "add a new item" will fail.

我了解您的痛点.不幸的是我们不能接受这个当前版本的变化.我们会在以后的版本中对其进行调查,并尝试提供更好的解决方案然后,例如提供浏览对话框使客户能够指定路径,或更好的错误消息指出一些解决方案,等等...

I understand your pain points. Unfortunately we cannot take this change in current release. We will investigate it in later releases and try to provide a better solution then,such as providing a browse dialog to enable customers to specify the path, or better error message to indicate some work around solution, etc...

你能试试当前的解决方法吗?阶段:GAC 您的自定义扩展汇编或将其复制到程序文件Microsoft Visual Studio9.0Common7IDE"?

Can you try the work around in current stage: GAC your custom extension assembly or copy it to "Program FilesMicrosoft Visual Studio 9.0Common7IDE"?

我们将提供自述文件以帮助其他可能遇到的客户同样的问题.

We will provide the readme to help other customers who may run into the same issue.

不幸的是,我似乎不太走运.

Unfortunately, it appears I'm out of luck on this one.

这篇关于为什么找不到我的自定义 WCF 行为扩展元素类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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