What is web service ?


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/&#8221;)]

[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

 

 

 

 

 

 

 

Step 4:

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();

}

}

Advertisements

14 Responses to “What is web service ?”

  1. Amir Says:

    Dear chandra,

    Would you please send me source code of this sample.
    my email is : clickmeplz@ymail.com

    Thaks a lot

  2. ajay kumar Says:

    Hey this document is very helpful for me,,,,,

    • Chandra Dev Says:

      I m really glad to hear that it helped you.Thank you for your comment.

  3. Religion And science Says:

    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!

  4. garcinia cambogia dosage for weight loss Says:

    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.

  5. deluxe Says:

    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?

  6. letter Says:

    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!

    • Chandra Dev Says:

      Hi

      Could you please share your website URL ?

  7. cell Says:

    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!

  8. Wieńce Says:

    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!

  9. here Says:

    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.

  10. lurlenedubay Says:

    Article writing is also a fun, if you be familiar with after that you can write otherwise it is
    complicated to write.

  11. adelaidastephen Says:

    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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: