Before reading this article, I suggest you read the previous parts of this series.
- Introduction to WCF: Part 1
- Introduction to Endpoint in WCF: Part 2
- How to Make Changes to WCF Service Without Breaking Client in WCF: Part 3
- Method Overloading in WCF: Part 4
- What a DataContract and DataMember are in WCF: Part 5
- KnownType Attribute in WCF: Part 6
- MessageContract in WCF: Part 7
According to the MSDN, Tracing enables you to view diagnostic information about a single request. It enables you to follow a service execution path, display diagnostic information at runtime and debug your application.
Let's create a WCF application and name it wcfService. Now here is the procedure to add two integer numbers.
Step 1
Delete the default Service1.svc and IService.cs.
Step 2
Add a new svc file and name it MathService.
Step 3
Delete the default service DoWork and add a new service. My IMathService.cs file will look like the following.
- using System.ServiceModel;
- namespace wcfService
- {
- [ServiceContract]
- public interface IMathService
- {
- [OperationContract]
- int AddTwoNo(int FirstNo, int Second);
- }
- }
Step 4
Let's make changes to MathService.svc.cs and implement the IMathService interface.
- using System;
- namespace wcfService
- {
- public class MathService : IMathService
- {
- public int AddTwoNo(int FirstNo, int Second)
- {
- return FirstNo + Second;
- }
- }
- }
As we know, the default binding of the WCF service is httpbasicbinding. So, let's run the application and test that is it working correctly.
Assign the value of the first and second numbers as 5 and 8 respectively and hit the Invoke button. The result is 13. That means that the service is working correctly.
Next, add a new MVC project to the solution mvcClient. I will select the template as basic. As per your requirements, it can be made individual.
Now, add a service reference. If you are a beginner in adding service references then please read my article on Introduction to WCF.
After adding the reference of my service, I will add a Model, View and Controller that are AddNumber, Index and Home respectively.
In AddNumber.cs
- namespace mvcClient.Models
- {
- public class AddNumber
- {
- public int FirstNo { get; set; }
- public int SecondNo { get; set; }
- }
- }

Pankajkumar PatelPosted Sep 13, 2019, 12:56 AM
Nice article
Sonu ChaudharyPosted Apr 4, 2016, 12:53 PM
good one
Santhakumar MunuswamyPosted May 19, 2015, 3:51 PM
Thanks for good work
Gowtham RajamanickamPosted May 19, 2015, 4:20 AM
Good one