Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 3945 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > How to consume third party webservice in Asp.net

How to consume third party webservice in Asp.net

1 vote(s)
Rating: 5 out of 5
Article posted by Vuyiswamb on 2/10/2010 | Views: 7724 | Category: ASP.NET | Level: Beginner red flag


A lot of newbie’s think of Web services as one complicated beast. I have seen Programmers who know OOP well be failed to understand web services. In this Article i will explain the usage of Web services. There are a lot sites that provide free web services, like Bible Search services, Weather Services, SMS sending services and more. You can look for one of the following services in the following site

Introduction

 A lot of newbie’s think of Web services as one complicated beast. I have seen Programmers who know OOP well be failed to understand web services. In this Article i will explain the usage of Web services. There are a lot sites that provide free web services, like Bible Search services, Weather Services, SMS sending services and more. You can look for one of the following services in the following site

Background


 In this Article I am going explain how to create your own date picker with the Controls you have on your Visual Studio tool.

Using the Code


We are going to user C# as our language.

Start

Open Visual Studio and Create a New Website. Automatically you will have an empty page defined for you like this

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

    </div>

    </form>

</body>

</html>

 

Go to Design View and you will notice there is nothing on your page. Now open your Toolbox and add a Label Control and a button. And after you have added these two Controls you should have something like this in your mark-up.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:Label ID="Label1" runat="server"></asp:Label>

        <br />

        <br />

    <asp:Button ID="Button1" Text ="Get Web Service" runat="server" />

    </div>

    </form>

</body>

</html>

 

 

The Next step is to consume the External Web Service. The Process is the same, just that now you need to get the webservice address from the third party. After get the address. Right click on your web Project and select the option as depicted in the following diagram


After you have selected the option you will be taken to another dialog box



In the URL part that is where you need to enter the address from the Third party provider of the webservice and click the green button. If the service really exists and there is nothing wrong with it. It will show you the Following

Now the external webservice has been found and it has exposed a function named “HelloWorld”. In the Web reference name change it to be a small one world that can be easily accessed will rename the “www.VuyiswaMaseko.com” to “www” and click ok and in your Solution explorer the following will be added.


Now it’s time to Access the Function in our Web Application. Remember we have a Button. Now double click the button on your design view and you will be taken to the Click even of the Button and write the Following Code.

protected void Button1_Click(object sender, EventArgs e)

    {

        www.Service obj = new www.Service();

        try

        {

            Label1.Text = obj.HelloWorld();

        }

        catch (ApplicationException ex)

        {

            Label1.Text = ex.Message;

        }

        finally

        {

            obj = null;

        }

    }

 

Now what we are doing here is we a re creating an Object of a class that is being exposed by the webserviceand accessing its funtions. A web service is like a Class that is in your project accessed via objects. But the Difference is that the webservice is in the different location. Next step is to run your web application and Click on the Button and the Following should happen

The “Hello World” is a coming from the external webservice. Think of Webservices as local classes that has functions that are ready to be used, but accessed from anywhere.

Conclusion

The Solution was simple and clear. This is how we consume third party and local webservice.

Thank you for visiting DotnetFunda.

Vuyiswa Maseko

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:8 year(s)
Home page:http://www.Dotnetfunda.com
Member since:Sunday, July 06, 2008
Level:NotApplicable
Status: [Member] [MVP] [Administrator]
Biography:Vuyiswa Junius Maseko is a programmer and a moderator in ".NetFunda. Vuyiswa has been developing for 8 years now. his major strength are C# 1.1,2.0,3.0,3.5 and sql and his interest are in Silverlight,WPF,C#. He has been doing a lot of Silverlight development. He has been using .net since the beta version of it. He is also an online Trainer at www.Itfunda.com. Thanks to people like Sheo Narayan (.Netfunda) , Chris Maunder (codeproject), Colin Angus Mackay (codeproject), Dave Kreskowiak (Codeproject),.They have made vuyiswa what he is today.
 Responses
Posted by: Raja | Posted on: 10 Feb 2010 06:18:34 AM

Wow!!!

Simple yet very nicely explained. Came late but a good start Vuyiswa.

Keep it up!



>> Write Response - Respond to this post and get points
Related Posts

Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email.

This article explains about the new property of ASP.NET 4.0

In this article we are going to see the fileupload without postback.. We are going to do this by using ICallbackEventHandler..

There are several ways to populate DropDownList control. In this article I have tried to cover some of them including populating DropDownList manually, programmatically, through xml, database, arraylist, hashtable. I have also covered how to specify different background color of every items of the DropDownList and how to generate DropDownList on the fly. At last I have covered how to get its index, text and value properties.

In this article we shall learn how to submit a page to the server when the TextBox value has changed, specify the width of the TextBox, specify the Maximum characters allowed for the TextBox, making the textbox readonly or disabled, and displaying multi-line textbox in asp.net.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 7:42:13 AM