开发者

ASMX to WCF conversion

I had an asmx service in .NET Framework 3.5 which I have now converted to .NET Framework 4.0. Now I want to run this service as WCF service with the same ASMX extension. I read a couple of blogs which have step y step procedure to convert them. However they all refer to .NET Framework 3.5. Here are the references I got from internet.

  • http://weblogs.manas.com.ar/waj/2007/05/31/asmx-to-wcf-migration/
  • http://blogs.msdn.com/b/wenlong/archive/2007/09/18/how-to-开发者_如何学Pythonuse-asmx-extension-to-handle-wcf-requests.aspx

I tried these and they work well with 3.5 framework but not with 4.0 framework. I got the error

Unable to cast object of type 'System.Web.Compilation.BuildResultCustomString' to type 'System.Web.Compilation.BuildResultCompiledType'.

on which I added httpHandler section and it was gone. However now I get a new error

Could not load type 'System.ServiceModel.Activation.HttpHandler' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Can anyone help me out with this error.


I got it working with aspNetCompatibilityEnabled set to 'true' like this:

Add a reference to:

System.ServiceModel.Activation

in your 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>


mind the type and publickeytoken changes in the handler!

It has to be 'System.ServiceModel.Activation' in stead of 'System.ServiceModel' and 'PublicKeyToken=31bf3856ad364e35' as Microsoft has split these into seperate assemblies


I think you may need to register the .NET 4 handlers in IIS properly. Run ServiceModelReg.exe -ia from the .NET 4 framework directory and see if it helps.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜