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

5 thoughts on “Expose WCF Service as Traditional Style Web Service .asmx

  1. 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

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