Client To a WebService

Objective:

Visual IDE

Step: 1 Create a Web-Site as shown below, and follow rest of the illustrations.

Now add a web reference

You may choose either local website or the service you might have created in another machine

As shown below one of the workstation has this service and set reference to the wsdl file by clicking on Add_Reference.

The illustration below shows that visual studio ide has created a discovery file to support runtime operation.

The followings are the steps to code that will call web services; as you code visual ide provides helps to pick the correct object.

Add a label in the form and add the following codes in the load function

Default.aspx

<%@ 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>mm.WebService1 Client1</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="L1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
 

Default.aspx.cs

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)
{
manas6.Service sc = new manas6.Service();
L1.Text += "The number obtained from the service " + sc.Addup(25, 50);
}
}
 

Step: 3 Run Time Views (Intranet Users Only)