Web Service
Web services are business logic components which provide functionality via the internet using standard protocols such as HTTP.
Web services uses simple Object access protocol (SOAP) in order to expose the business functionality. SOAP is the platform independent so consumer of web service can take service on any platform. i.e Unix,Linux etc.
Uses Of web service
It is used to communicate with different applications which has been developed on different platform using different technology.
How to Create Simple web service to fill GridView in Asp.net 3.5 ?
These are the following steps to create the web service
Step1. Add the web service file as shown in fig1
Step 2. Write the following code in webservice.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for WebService2
/// </summary>
[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 WebService2 : System.Web.Services.WebService {
public WebService2 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public DataSet GetEmpName()
{
SqlConnection con = new SqlConnection(“Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True”);
SqlCommand cmd = new SqlCommand(“Select *from tblEmp”, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
Step 3: Compile the web service file as shown in fig2
Click on getEmpName method then Click on “Invoke” as shown in fig3. If the web service is correct then you will get the EmpName in Xml formate.
Then copy the webservice URL I.e http://localhost:1036/TestWebService/WebService2.asmx
Step 5: Go to Solution exp then select your project ->Right click on project -> add web reference. Then you get like this
Then you will get .disco and .wsdl file in Solution explore of project.
Step 6: Go to default page, Take a gridview control and write the following code in code behind file for filling the gridview Control.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
fillgridview();
}
protected void fillgridview()
{
WsTest.WebService2 ws = new WsTest.WebService2();
GridView1.DataSource = ws.GetEmpName();
GridView1.DataBind();
}
}
Dear chandra,
Would you please send me source code of this sample.
my email is : clickmeplz@ymail.com
Thaks a lot
Hi
You can also download from this link
http://cid-4b1f6c3e92f6522c.office.live.com/browse.aspx/.Public
Hey this document is very helpful for me,,,,,
I m really glad to hear that it helped you.Thank you for your comment.
A person necessarily assist to make severely posts I’d state. This is the first time I frequented your website page and up to now? I surprised with the research you made to create this particular put up incredible. Excellent process!
Does your blog have a contact page? I’m having problems locating it but, I’d like to send you an email.
I’ve got some recommendations for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it develop over time.
I’m really enjoying the theme/design of your site.
Do you ever run into any browser compatibility issues? A handful of my blog readers
have complained about my blog not operating correctly
in Explorer but looks great in Chrome. Do you have any suggestions to help fix this problem?
Hey there! I know this is kinda off topic however I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest writing a blog article
or vice-versa? My website discusses a lot of the same subjects as
yours and I think we could greatly benefit from each other.
If you’re interested feel free to shoot me an e-mail.
I look forward to hearing from you! Excellent blog by the way!
Hi
Could you please share your website URL ?
Hello! Quick question that’s entirely off topic. Do you know how to
make your site mobile friendly? My website looks weird when viewing from my apple iphone.
I’m trying to find a template or plugin that might be able to resolve this issue.
If you have any recommendations, please share.
Thanks!
Spot on with this write-up, I seriously think
this site needs a lot more attention. I’ll probably be back again to
read through more, thanks for the information!
I have been browsing online greater tyan 3 hours nowadays, but I by no
means discovered any fascinating article likke yours.
It is lovely worth sufficient foor me. In my opinion, if all
web owners and loggers made just rightt content
as you did, the internet can be a lot more useful than ever before.
Article writing is also a fun, if you be familiar with after that you can write otherwise it is
complicated to write.
You have made some good points there. I looked on the internet for more information about the issue and found
most individuals will go along with your views on this site.
Amazing blog! I Loved reading this article.
This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! Keep up the good work.
Amazing blog! I Loved reading this article.
there is no download link but it says Download latest release from GitHub then you press it and it wont let you save it or open and I really just want to know whats going on