Share via


WCF Service with .asmx extensions

We already have quite a large number of ASMX services and clients. One major point to be kept in mind is that WCF and asmx services can co-exist without any problem and migration to WCF should be your first and only choice unless there is a reason like using security that you do not have already. Or other WS protocols that you need for expanding your serivce.

When migrating there are a number of scenarios one can encounter. One of them is moving an asmx service to WCF withouth changing the undelying client. This would also include not changing the endpoint address to which the client talks to. Now if the client points to something like https://MyServer.com/Service.asmx how can you make this a WCF service? There are 2 main scenarios when doing this.

 Without AspNetCompatibility mode.

This is a rather strainght forward approach and can be achieved through the following steps.

1. Add a service host file called service.asmx with the following

<%@ServiceHost language=c# Debug="true" Service="WCFAspCompat.service1" %>

2. Add the following to your web.config file

<system.web>

    <compilation>

      <buildProviders>

        <remove extension=".asmx"/>

        <add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

      </buildProviders>

    </compilation>

  </system.web>

 

 

With AspNetCompatibility

This requires one more configuration for the httpHandlers and can be achieved with the following steps.

1. Add a service host file called service.asmx with the following

<%@ServiceHost language=c# Debug="true" Service="WCFAspCompat.service1" %>

2. You have to remove the .asmx handler initially. Add the following to you Web.config to get this working.

 

<system.web>

    <httpHandlers>

      <remove path="*.asmx" verb="*"></remove>

      <add path="*.asmx" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

          validate="false" />

    </httpHandlers>

    <compilation>

      <buildProviders>

        <remove extension=".asmx"/>

        <add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

      </buildProviders>

    </compilation>

  </system.web>

3. Get your service setup as a aspNet Compatibile service refer this post.