Exposing WCF Service For Both WCF Web Service and ASP.NET Web Service Clients

Here you will learn how to make a WCF application that can act as a WCF Web Service and ASP.NET Web Service.

There are Some Client which deals with calling external service.

External service can be WCF or Simple Web Service.

There are some client who still can only connect to web service.

So it’s better to create a service for both WCF clients as well as Web service client.

As we know WCF is better than web service as compared to their features.

Let’s Make a WCF application which can act as .svc as well as .asmx

Steps to be followed

Step 1: Select new project in Visual studio and select WCF > WCF Service Application

Name the project and solution.



Step 2: Now Right click on project and select add > New Item (CTRL + shift + A).

Add new web service file (.asmx). And name it as wcfasasmx.



Step 3: now open the node of web wcfasasmx.asmx file and delete wcfasasmx.asmx.cs file



Step 4: now once .cs file is deleted. You will find wcfasasmx.asmx file.

Double click it and modify it

remove code behind element from Web Service attribute.

Change class name to your WCF class Full name (Namespace + Class name).

I have WCF class name as Service1 and this class is present in WCFasASMX NameSpace.

So I changed class name as WCFasASMX.Service1.



Step 5:
Now Some changes in Code side.

In web.config in <system.web> Tag add following code

  1. <system.web>  
  2.    <webServices>  
  3.       <conformanceWarnings>  
  4.          <remove name='BasicProfile1_1'/>  
  5.       </conformanceWarnings>  
  6.    </webServices>  
  7. </system.web>  
Add following 2 attribute on interface (on ServiceContract of WCF).
  1. [WebService(Name = "Service1")]  
  2. [WebServiceBinding(Name = "Service1",  
  3. ConformsTo = WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true)]   
Add [WebMethod] attribute on each operation contract
  1. [OperationContract]  
  2. [WebMethod]  
  3. string GetData(int value);  
Step 6: Now run WCFasASMX.aspx in browser and Boom. It’s done



You can test it.