Thursday, 2 August 2012

Web Services 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). SOAP is a W3C submitted note (as of May 2000) that uses standards based technologies (XML for data description and HTTP for transport) to encode and transmit application data.
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).

Try simple code :

ASPX :->

<html xmlns="">
head runat="server"><title></title></
body><form id="form1" runat="server"><div><asp:GridView ID="GridView1" runat="server"><Columns><asp:BoundField DataField="id" HeaderText="ID" /><asp:BoundField DataField="f_name" HeaderText="Firts name" /><asp:BoundField DataField="adds" HeaderText="ADDS" /></Columns></asp:GridView><asp:Button ID="Button1" runat="server" Text="Click" onclick="Button1_Click" /></div></form></

CS ->

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using webServiceTrial;namespace webServiceTrial{

public partial class _Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){

protected void Button1_Click(object sender, EventArgs e){
WebService1 wrr = new webServiceTrial.WebService1();GridView1.DataSource = wrr.getDetails();

WebService asmx :-?

using System.Web.Services;using System.Data;using System.Data.Sql;using System.Data.SqlClient;namespace webServiceTrial{

/// <summary>/// Summary description for WebService1/// </summary>[WebService(Namespace = "")][
WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.
// 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 WebService1 : System.Web.Services.WebService{
public string HelloWorld(){

return "Hello World";}
public DataSet getDetails(){

SqlConnection conn;
SqlDataAdapter myDataAdapter;
DataSet myDataSet;
const string cmdString = "Select * From Info";conn =
new SqlConnection("Data Source=ADS;Initial Catalog=TestApp;Persist Security Info=True;User ID=Nihar.Kulkarni;Password=bflmcd");myDataAdapter =
new SqlDataAdapter(cmdString, conn);myDataSet =
new DataSet();myDataAdapter.Fill(myDataSet,
return myDataSet;

No comments:

Post a Comment