Home > .NET, C#, Compatibility, WCF, Web Service > Expose WCF Service as Traditional Style Web Service .asmx

Expose WCF Service as Traditional Style Web Service .asmx

WCF service can be exposed as traditional style web service .asmx. I had to do this because of integration issue with Tibco.

My setup on the WCF Service is with 2 projects:
1. WCF Service Library
2. Web Site to host the WCF Service

To expose WCF Service as .asmx web service
1.  Add these tags in your service interface declaration.

[ServiceContract]
[WebService(Name="Service")]
[WebServiceBinding(Name = "Service", ConformsTo = WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true)]
public interface IService
{
    [OperationContract]
    [WebMethod]
    string HelloWorld();
}

public class Service : IService
{
    public string HelloWorld()
    {
        return "Hello World!";
    }
}

2. Add reference from ServiceLibrary to the Service

3. Create .asmx file in website; change class to point to the right assembly and class; remove CodeBehind attribute

<%@ WebService Language="C#" Class="ServiceLibrary.Service" %>

4. Debug and Test

Be aware that some of the WCF capabilities will not be compatible with the traditional web service .asmx.

Thanks to kjellsj. See his post here.

Cheers – Sy

About these ads
  1. Joel
    27/01/2012 at 03:36

    My initial tests using this method worked great. Thank you so much!

  2. Ammar
    14/12/2012 at 22:06

    What is the directory name for [WebService], [WebServiceBinding] and [WebMethod]?

    • 17/12/2012 at 08:59

      Hi Ammar,

      I’m sorry I don’t understand what you mean by directory name for [WebService].

      Sy

  3. Chuck Bevitt
    10/07/2013 at 01:25

    Thanks much, worked great. One note: the web service will have “http://tempuri.org/” as its namespace by default. The way to fix this is to add the [Webservice] attribute to the class as well as to the interface and to specify the Namespace there, as:

    [WebService(Name = "MyService", Namespace = "http:\\MyService.net")]
    public class MyServiceClass : IMyServiceClass

    • 10/07/2013 at 13:05

      Hi Chuck, Thanks for the comment and note. Much appreciated, Sy.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 112 other followers

%d bloggers like this: