【问题标题】:ASMX to WCF conversionASMX 到 WCF 的转换
【发布时间】:2011-04-16 12:01:07
【问题描述】:

我在 .NET Framework 3.5 中有一个 asmx 服务,现在我已将其转换为 .NET Framework 4.0。现在我想将此服务作为具有相同 ASMX 扩展名的 WCF 服务运行。我阅读了一些博客,其中包含逐步转换它们的步骤。但是,它们都指的是 .NET Framework 3.5。以下是我从网上得到的参考资料。

我尝试了这些,它们在 3.5 框架下运行良好,但在 4.0 框架下运行良好。我得到了错误

无法转换类型的对象 'System.Web.Compilation.BuildResultCustomString' 输入 'System.Web.Compilation.BuildResultCompiledType'。

我在上面添加了 httpHandler 部分,但它已经消失了。但是现在我收到一个新错误

无法加载类型 'System.ServiceModel.Activation.HttpHandler' 从程序集'System.ServiceModel, 版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089'

谁能帮我解决这个错误。

【问题讨论】:

  • 我有一个 Framework 3.5 wcf 服务,带有 asmx 扩​​展,运行良好。只是我将我的项目从 3.5 转换为 4.0,它相应地修改了 web.config。我做了上面指定的必要更改,但给出了错误。你能帮忙吗?

标签: wcf migration asmx


【解决方案1】:

我将它与 aspNetCompatibilityEnabled 设置为 'true' 一起使用,如下所示:

添加对以下内容的引用:

System.ServiceModel.Activation

在您的 web.config 中:

<system.web>
<compilation debug="true" targetFramework="4.0">
  <buildProviders>
    <remove extension=".asmx"/>
    <add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </buildProviders>
</compilation>
</system.web>

<system.webServer>
<handlers>
  <remove name="WebServiceHandlerFactory-Integrated"/>
  <add name="MyNewAsmxHandler" path="*.asmx" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>


注意处理程序中的类型和 publickeytoken 更改!

它必须是 'System.ServiceModel.Activation' 而不是 'System.ServiceModel' 和 ' PublicKeyToken=31bf3856ad364e35' 因为微软已将它们拆分为单独的程序集

【讨论】:

    【解决方案2】:

    我认为您可能需要在 IIS 中正确注册 .NET 4 处理程序。从 .NET 4 框架目录运行 ServiceModelReg.exe -ia 看看是否有帮助。

    C:\Windows\Microsoft.NET\Framework\v4.0.30319>ServiceModelReg.exe /?
    Microsoft (R) WCF/WF registration tool version 4.0.0.0
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Administration utility that manages the installation and uninstallation of
    WCF and WF components on a single machine.
    
    Usage:
        ServiceModelReg.exe [(-ia|-ua|-r)|((-i|-u) -c:<command>)] [-v|-q] [-nologo]
    [-h]
      -ia
        Install all components
      -ua
        Uninstall all components
      -r
        Extended only.  Repairs all components
      -i
        Install components specified with -c
      -u
        Uninstall components specified with -c
      -c:<component>
        Install/uninstall a component:
          httpnamespace        - HTTP namespace reservation
          tcpportsharing       - TCP port sharing service
          tcpactivation        - TCP activation service (unsupported on .NET 4 Clien
    t Profile)
          namedpipeactivation  - Named pipe activation service (unsupported on .NET
    4 Client Profile)
          msmqactivation       - MSMQ activation service (unsupported on .NET 4 Clie
    nt Profile)
          etw                  - ETW event tracing manifests (Windows Vista or later
    )
        Can be used to install several components at the same time
      -q
        Quiet mode (only error logging)
      -v
        Verbose mode
      -nologo
        Suppress the copyright and banner message
      -h
        Displays this help text.
    
    Examples:
        ServiceModelReg.exe -ia
          Installs all components
        ServiceModelReg.exe -i -c:httpnamespace -c:etw
          Installs HTTP namespace reservation and ETW manifest
        ServiceModelReg.exe -u -c:etw
          Uninstalls ETW manifests
        ServiceModelReg.exe -r
          Repairs an extended install
    

    【讨论】:

    • 我尝试在 IIS 中注册 .NET 4 处理程序。我运行了命令ServiceModelReg.exe -ia,它给了我警告[Warning]The HTTP namespace reservation already exists. 我试图通过ServiceModelReg.exe -ua 注销.Net 4 处理程序,我收到警告[Warning]A previous version of Windows Communication Foundation was detected. The HTTP namespace reservation was not removed. 再次注册处理程序给了我同样的警告[Warning]The HTTP namespace reservation already exists.
    • 这实际上是预期的——它不会删除命名空间保留,因为它不想破坏您也已安装的 .NET 3 WCF。忽略那些警告。你的问题现在解决了吗?
    • 非常感谢您为我指明了正确的方向。我能够解决其中一个 cmets 的错误。我删除了aspNetCompatibilityEnabled="true" 属性,一切似乎都按预期工作。
    猜你喜欢
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    相关资源
    最近更新 更多