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