Monday 23 April 2012

How to create web services in asp.net || What is web service || How webservice is Work || How to consume Webserices || How to create simple webservice..

Hi Friends, In this article i will explain about how to create simple webservice in .NET.
In previous article i explained about What is webservice? What is WCF? Difference between webservice and WCF.

What is webService?
Webservice is used to convert your applications into web applications.
Webservices are  integrate web based application using XML,SOAP,SWDL and UDDI .
XML is used to tag the data like <webservice >hi</webservice>
SOAP is used to transfer the data.
WSDL is used for describing the services .
UDDI is used to listing the web services.
How webservice is work?
The basic Web services platform is XML + HTTP.
XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions.
The HTTP protocol is the most used Internet protocol.
Web services platform elements:
  • SOAP (Simple Object Access Protocol)
  • UDDI (Universal Description, Discovery and Integration)
  • WSDL (Web Services Description Language)
Now we will know the create web service.
First of all create  ASP.NET WEB SITE
File   -->  New   -->  Website  --> enter website name  --> OK
Then the website is created.

Add one webservice file.
Right click on website   -->  Add New Item   --> Web Service  --> enter the name   --> OK
Then run the page.

Write the below code in webservice file
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService1
    Inherits System.Web.Services.WebService

    <WebMethod()> _
 Public Function simpleMethod(ByVal srt As [String]) As String
        Return "Hello " & Convert.ToString(srt)
    End Function

    <WebMethod()> _
    Public Function anotherSimpleMethod(ByVal firstNum As Integer, ByVal secondNum As Integer) As Integer
        Return firstNum + secondNum
    End Function

End Class



Add this webservice to the your website.

Right click on website -->Add Web reference  -->  copy and paste the above URL--> GO   --> Add Reference
Then the webservice is added to your website.
 Take one .aspx page
Right click on website  -->  Add New Item  -->  Web Form  --> enter name   --> OK

Copy and Paste the below code in .aspx.vb page
Imports localhost
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim webservice As New WebService1()

        Dim srt As String = webservice.simpleMethod("Kishore")
        Response.Write(srt)
        Response.Write(webservice.anotherSimpleMethod(4, 3))
    End Sub
End Class

And run the page.
 
"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook pageAspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog  for more articles." 

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.