Thursday, July 5, 2012

Web service in asp.net


A Web Service is programmable application logic accessible via standard Web protocols. One of these Web protocols is the Simple Object Access Protocol (SOAP)

Consumers of a Web Service do not need to know anything about the platform, object model, or programming language used to

implement the service; they only need to understand how to send and receive SOAP messages (HTTP and XML).



A Web Service Example

In the following example we will use ASP.NET to create a simple Web Service that adds two numbers

VB.
<%@ WebService Language="VB" Class="MyMath" %>
Public Class MyMath
  Public Function Add(a As Integer, b As Integer) As Integer
    Return a + b
  End Function
End Class


C#.

<%@ WebService Language="VB" Class="MyMath" %>
Public Class MyMath
{

[WebMethod]
  Public int  Add( Int a, Int b )
{
    Return a + b;
}
 
}





Consuming (Calling) Web Service


Web Services can be consumed in 2 ways :

    Select Project / Web site > right-click > Add Web Reference

        Follow the wizard. If you select option “Web service in this solution”, it will do following things

            Creates App_WebReferences folder
            Create localhost having 2 files – .disco & .wsdl
            Then write following code in .aspx > Button click event :
            [Here, WebService is the name of the web service.]

No comments:

Post a Comment

Save a PDF generated from html2pdf in C#, MVC , html2pdf , Ajax code

 To save on server or disk a PDF generated from HTML in C# code example, you can use the      html2pdf js script     html2pdf   converts any...