Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Sunday, 24 December 2017

Creating WCF Service with wsHttpBinding and webHttpBinding together

In this tutorial, I am going to explain you how to create .NET WCF Service with wsHttpBinding and webHttpBinding together in single WCF application. Below topics will be covered in this tutorial.

  • Creating new WCF Service application project
  • Creating simple calculator service
  • Creating complex / CompositeType calculator service
  • Configuring service with wsHttpBinding and webHttpBinding
  • Calling simple and complex service using .NET application by creating Proxy Class (wsHttpBinding)
  • Calling simple and complex service using REST client like POSTMAN (webHttpBinding)
  • Calling simple and complex service using jQuery (webHttpBinding)

Creating new WCF Service application project

I will be using visual studio 2013 and .NET framework 4.5.
Go to FileNewProject. A new window will be open as shown below.
Now go to Visual C# and search for WCF Service Application and give project name and click on OK .

Creating WCF Service application

Now a wcf service will be created with default template as shown below.

WCF Service folder structure

1) Now rename IService1.cs to ICalc.cs and Service1.svc to Calc.svc.
2) Now right click on Calc.svc, go to View Markup and change service from Service="WcfService1.Service1" to Service="WcfService1.Calc".

Creating simple and Complex calculator service

Now open ICalc.cs file, delete all the default code generated and replace its with new code as shown below. Here we have declared two method Calculator1 and Calculator2 inside inteface, both are decorated with POST verb and returns Json data. Calculator1 method accepts two integer parameter where as Calculator2 method accepts a complex class objects and both returns addition of two numbers.

ICalc.cs Code
Share:

Email Subscription

Subscribe to our newsletter to get the latest articles directly into your inbox

Blog Archive

Ads By Chitika