我在.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,文化=中立, 公钥= b77a5c561934e089'
任何人都可以帮我解决这个错误。
答案 0 :(得分:4)
我使用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'和'< strong> PublicKeyToken = 31bf3856ad364e35 '因为Microsoft已将这些分成单独的程序集
答案 1 :(得分:1)
我认为您可能需要在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