AssemblyBinding BindingRedirect 不适用于 serviceModel 中配置的行为。 (Wcf)

发布于 2024-12-17 20:31:26 字数 2809 浏览 1 评论 0原文

我们有很多 Web 应用程序,使用自定义部分(在其 web.config 中)进行配置,这些部分依赖于 machine.config 中声明的 sectionHandlers

由于我们有这些 sectionHandlers 的多个版本,因此想要使用新 sectionHandlers 的应用程序必须使用标签 < assemblyBinding xmlns= 强制“程序集重定向” web.config 中的“urn:schemas-microsoft-com:asm.v1”>。只要还有其他应用程序使用最旧的版本,我们确实无法修改 machine.configsectionHandlers 的声明。

绑定重定向适用于使用前面提到的标记的应用程序加载的所有程序集 - 除了包含用于在 web.config 的 system.serviceModel 部分中定义 WCF 行为的类型的程序集。

例如,我们的一些应用程序正在使用名为 mainframeFormatter 的自定义行为扩展(请参阅后面示例中的 web.config)。将 bindingRedirect 从包含 mainframeFormatter 类型的程序集版本 1.1.0.0 添加到版本 1.2.0.0 时,我们收到以下错误:

创建配置节处理程序时发生错误 system.serviceModel/behaviors:扩展元素'mainframeFormatter' 无法添加到此元素。验证扩展名是否为 在扩展集合中注册 system.serviceModel/extensions/behaviorExtensions。

请注意,我们只有“行为”的问题,而不是“绑定”的问题。 这是绑定重定向与 WCF 行为的预期行为还是一个错误?

以下是使用绑定重定向时无法解析的 web.config 示例:

<system.serviceModel>
  <extensions>
    <behaviorExtensions>
      <add name="mainframeFormatter"
              type="Framework.Communication.Mainframe.ClientEndpointBehaviorExtensionElement,
                       Framework.Communication.Mainframe, Version=1.1.0.0, Culture=neutral,
                       PublicKeyToken=f510307097254a31"/>
    </behaviorExtensions>
    <bindingExtensions>
      <add name="mainframeBinding" 
              type="Framework.Communication.Mainframe.BindingCollectionElement,
                       Framework.Communication.Mainframe, Version=1.1.0.0, Culture=neutral,
                       PublicKeyToken=f510307097254a31"/>
    </bindingExtensions>
  </extensions>

  <behaviors>
    <endpointBehaviors>
      <behavior name="ClientEndpointBehavior">
        <mainframeFormatter />  <--- Problem is on parsing this with assemblyBinding enabled
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <bindings>
    <mainframeBinding>
      <binding name="MyCustomBinding"/>
    </mainframeBinding>
  </bindings>

</system.serviceModel>

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Framework.Communication.Mainframe"
                               publicKeyToken="f510307097254a31" />
      <bindingRedirect oldVersion="1.1.0.0" newVersion="1.2.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

我知道更改 behaviorExtension 设置中的版本可以解决该问题。但我很好奇为什么重定向不起作用。

We have a lot of web applications, configured using custom sections (in their web.config) that depend on sectionHandlers declared in the machine.config.

As we have several versions of these sectionHandlers, applications that want to use a new sectionHandlers have to force "assembly redirection" by using the tag <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> in their web.config. We can indeed not modify the declaration of the sectionHandlers in the machine.config as long as there are still other applications using the oldest version.

The binding redirection works fine for all the assemblies loaded by the applications using the tag mentioned before - except for the assemblies containing types used to define a WCF behavior in the web.config's system.serviceModel section.

For example, some of our applications are using a custom behavior Extension named mainframeFormatter (See in the web.config in the example here after). When adding a bindingRedirect from a version 1.1.0.0 of the assembly containing the type mainframeFormatter to a version 1.2.0.0, we get the following error:

An error occurred creating the configuration section handler for
system.serviceModel/behaviors: Extension element'mainframeFormatter'
cannot be added to this element. Verify that the extension is
registered in the extension collection at
system.serviceModel/extensions/behaviorExtensions.

Notice that we only have the problem with the "behaviors" and not with the "bindings".
Is this the expected behavior of the Binding Redirection with WCF behaviors or is this a bug ?

Here's a sample of web.config which fails to be parsed when using binding redirection:

<system.serviceModel>
  <extensions>
    <behaviorExtensions>
      <add name="mainframeFormatter"
              type="Framework.Communication.Mainframe.ClientEndpointBehaviorExtensionElement,
                       Framework.Communication.Mainframe, Version=1.1.0.0, Culture=neutral,
                       PublicKeyToken=f510307097254a31"/>
    </behaviorExtensions>
    <bindingExtensions>
      <add name="mainframeBinding" 
              type="Framework.Communication.Mainframe.BindingCollectionElement,
                       Framework.Communication.Mainframe, Version=1.1.0.0, Culture=neutral,
                       PublicKeyToken=f510307097254a31"/>
    </bindingExtensions>
  </extensions>

  <behaviors>
    <endpointBehaviors>
      <behavior name="ClientEndpointBehavior">
        <mainframeFormatter />  <--- Problem is on parsing this with assemblyBinding enabled
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <bindings>
    <mainframeBinding>
      <binding name="MyCustomBinding"/>
    </mainframeBinding>
  </bindings>

</system.serviceModel>

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Framework.Communication.Mainframe"
                               publicKeyToken="f510307097254a31" />
      <bindingRedirect oldVersion="1.1.0.0" newVersion="1.2.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

I know that changing the version in the behaviorExtension settings solves the problem. But I am curious why the redirection does not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小伙你站住 2024-12-24 20:31:26

他们将很快提供修补程序。

They will provide a hotfix soon.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文