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

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

问题描述

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



在类库中,我称之为Framework,我有一个端点行为(IEndpointBehavior实现)和一个配置元素(派生自BehaviorExtensionsElement的类)。配置元素是这样的,所以我可以通过配置将端点行为附加到服务。



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

 < system.serviceModel> 
<行为>
< endpointBehaviors>
< behavior name =MyEndpointBehavior>
< enableWebScript />
< customEndpointBehavior />
< / behavior>
< / endpointBehaviors>
< / behavior>
< 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服务正确使用我的自定义配置的端点行为。



问题是当我尝试添加一个新的AJAX WCF服务时。如果我添加 - >新项目...并选择启用AJAX的WCF服务,我可以看到它添加.svc文件和codebehind,但是当它更新web.config文件时,我得到这个错误:


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



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


显然,配置是完全有效的,因为它在运行时工作得很好。如果我暂时从我的行为配置中删除元素,然后添加启用了AJAX的WCF服务,一切都没有任何困难。



不幸的是,在一个更大的项目中,我们将拥有各种配置的多种服务,临时删除所有的自定义行为将是容易出错的。虽然我意识到我可以没有使用向导,而是手动完成所有操作,但并不是每个人都可以,而且只要使用这个产品即可使用这个产品,这是很好的 - 向导和所有。



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



更新/澄清:




  • 它在运行时工作,而不是设计时间。

  • 当我尝试添加服务时,web项目的bin文件夹。

  • 虽然我可以手动添加服务(没有配置),我需要开箱即用的项目模板来工作 - 这是问题的整个目标。

  • 这个问题在Visual Studio 2008中出现。在VS 2010中,这似乎已经解决了。



我在Microsoft Connect上提交了此问题 a原来你要么将自定义配置元素放在GAC中,要么放在IDE文件夹中。他们不会修复它,至少现在。我已经发布了他们提供的解决方案作为这个问题的答案。

解决方案

Per 解决方法 Microsoft发布在连接问题我提交了这个,这是一个已知的问题,不会有任何解决方案,至少在当前版本:


无法添加新的
服务项目的原因:添加新项目
和更新配置文件
系统将尝试加载
配置文件,所以它将尝试
搜索并加载该配置文件中
cusom扩展的汇编。
只有在汇编为
GACed或位于同一路径
作为vs exe(程序文件\Microsoft
Visual Studio 9.0 \Common7 \IDE ),
系统可以找到它。否则,将弹出
错误对话框,并且添加
新项目将失败。



我明白你的痛点。
不幸的是,我们不能在当前版本中取得这个
的更改。我们将
在以后的版本中调查,
尝试提供一个更好的解决方案
,如提供一个浏览对话框
,使客户能够指定
路径,或更好的错误消息到
表示解决方案的一些工作,
等...



你可以尝试在当前的
阶段:GAC您的自定义扩展
程序集或将其复制到Program
Files \Microsoft Visual Studio
9.0\Common7\IDE?



我们将提供自述以帮助
其他可能遇到
相同问题的客户。


不幸的是,似乎我没有运气。


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.

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.

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>

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

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:

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

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

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.

Why isn't my custom WCF behavior extension element type being found?

Updates/clarifications:

  • It does work at runtime, just not design time.
  • The Framework assembly is in the web project's bin folder when I attempt to add the service.
  • While I could add services manually ("without configuration"), I need the out-of-the-box item template to work - that's the whole goal of the question.
  • This issue is being seen in Visual Studio 2008. In VS 2010 this appears to be resolved.

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 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:

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 Files\Microsoft Visual Studio 9.0\Common7\IDE), 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...

Can you try the work around in current stage: GAC your custom extension assembly or copy it to "Program Files\Microsoft Visual Studio 9.0\Common7\IDE"?

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天全站免登陆