Web Service - How to use (create, consume, invoke) web service in asp.net
Step [Create New Web Site]
IDE(Visiul Web Developer 2008 Express Edition)-> File-> New Web Site-> WebServiceExample(name)-> Language(Visual C#) ->Save
Add New Item-> Web Service -> Name(BookName.asmx)-> UnCheck Place code in separate file-> Save
BookName.asmx
<%@ WebService Language="C#" Class="BookName" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class BookName : System.Web.Services.WebService {
[WebMethod]
public string GetBookName() {
return "Adobe Illustrator CS4 Wow! Book, The";
}
}
Step [Add Web Reference]
WebSite(Menu)-> Add Web Reference-> Select Web services in this solution-> Select BookName->
Web reference name(BookService) -> Click Add Reference
UsingWebService.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
BookService.BookName ws = new BookService.BookName();
Label1.Text = ws.GetBookName();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Web Service - How to use (create, consume, invoke) web service in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">Web Service Example: How To Use Web Service</h2>
<hr width="500" align="left" color="SkyBlue" />
<br /><br />
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
Font-Italic="true"
ForeColor="OrangeRed"
Font-Names="Comic Sans MS"
Font-Size="Large"
>
</asp:Label>
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="DodgerBlue"
Text="Consume Web Service and Get Book Name"
OnClick="Button1_Click"
Height="45"
/>
</div>
</form>
</body>
</html>

