Thursday, April 25, 2019

.Net REST Web service using Visual Studio

Step 1:- Creat a new project
Image1Image2Image3
click on Create Button
Image4Image5Image6
Step 2:-
Now we will create the below classes for handling our GET, POST, PUT, and DELETE services from client
Right-click on the Models folder from the project explorer window and select Add=>Class
Image7Image8

Modify Employee Class as given below

Image9
Step3:-
We will have one class that will containt he original logic that will perform GET/POST/PUT/DELETE Operation
i.e.
GET:- To get all the information of the resource.
POST:- TO create the resource
PUT:- To Update the resource if present or cretae it if not present.
DELETE:- To delete the resource.
Image10
Step 4:-
Now lets develop the controller. This is the front facing class of server to client i.e. all the request are first diverted to this controler and depending on it further corresponding business logic class method is called.
We will first creat the GET Controller class. Right-click on the Controllers folder and select Add=>Controller. From the below window, select Web API 2 Controller — Empty
Image11Image12
Click Add button

Image13Image14Image15Image16
Hurrey !!! you are done with exposing your first REST service. Run the application and hit the url
Same way we need to create Controller for all the different operaiton i.e. PUT/POST/DELETE.
Note:- Please see the url
http://localhost:55486/api/employeeretrive
employteeretrive = EmployeeRetriveController

Wednesday, April 24, 2019

Creating SOAP Web service and Consuming it using Microsoft Visual Studio

Step 1:- Make sure to install Visual Studio from site belwo site vs_community__1147343234.1553667520.exe. Take Community Platform and install it. During installtion use .net Framework as core. If asked for restart at the end please do the same.
https://visualstudio.microsoft.com/downloads/
Step 2:- Follow the following Step to create SOAP Web service now.
Image1
Click on Create New project
Image2Image3Image4Image5Image6
Right click Project -->Add-->New Item-->Web Service ASMX
Image7
click Add Button and you are done with your Server side code ready for exposing your first SOAP WSDL Web Service.
What it do? It return you hello world text in soap.Lets check it!!!!
Image8
Run the Project using F5 button and you will be able to see the your web service on the page
Image9Image10
Click on HelloWorld
Image11
Click on Invoke button and your webservice will be invoked

Image12
Step 2:- Now let try to create our own Web service method. Lets call it as add which will take list as in input and will give addition of all the item in the list as result.

Image13
Now run the applciation using F5 and we will be able to see Add method on the screen.
Image14
Click on add method and you will be see it SOAP 1.1 and 1.2 version.
Image15
Step 3:- Now lets use this SOAP WSDL xml for generating client code to call this Add method and get the response.
For that right click on project-->"Add Service Reference"
Image16
click on go and you will be able to see all the Method exposed
Image17
Click Ok
We also need to add the webform page to our project i.e. WebForm.aspx to give the ui for calling the SOAP Web service.
Right Click Project -> Add --> new Item --> select Web Form

Image18
click Add

Image19
We need to add folloing code in its correspondign .cs file i.e. WebForm.aspx.cs

Image20Image21
Run the application by clicking F5

Image22
click on Button and see the result for the SOAP Web service ADD method which you had exposed.

Image23