[C#] <%@ Page Language="C#" %> <%@ Import Namespace="System.Net" %> <html> <script language="C#" runat="server"> void EnterBtn_Click(Object Src, EventArgs E) { MyMath.Math math = new MyMath.Math(); // Call to Add XML Web service method asynchronously // and then wait for it to complete. IAsyncResult result = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), null, null); // Wait for asynchronous call to complete. result.AsyncWaitHandle.WaitOne(); // Complete the asynchronous call to Add XML Web service method. float total = math.EndAdd(result); // Display results in a Label control. Total.Text = "Total: " + total.ToString(); } </script> <body> <form action="MathClient.aspx" runat=server> <font face="Verdana"> Enter the two numbers you want to add and then press the Total button. <p> Number 1: <asp:textbox id="Num1" runat=server/> + Number 2: <asp:textbox id="Num2" runat=server/> = <asp:button id="Total_Button" text="Total" OnClick="EnterBtn_Click" runat=server/> <p> <asp:label id="Total" runat=server/> </font> </form> </body> </html> [Visual Basic] <%@ Page Language="VB" %> <%@ Import Namespace="System.Net" %> <html> <script language="VB" runat="server"> Sub EnterBtn_Click(Src As Object, E As EventArgs) Dim math As New MyMath.Math() ' Call to Add XML Web service method asynchronously ' and then wait for it to complete. Dim result As IAsyncResult = _ math.BeginAdd(Convert.ToInt32(Num1.Text), _ Convert.ToInt32(Num2.Text), _ Nothing, _ Nothing) ' Wait for asynchronous call to complete. result.AsyncWaitHandle.WaitOne() ' Complete the asynchronous call to Add XML Web service method. Dim addtotal As Single = math.EndAdd(result) ' Display results in a Label control. Total.Text = "Total: " & addtotal.ToString() End Sub </script> <body> <form action="MathClient.aspx" runat=server> <font face="Verdana"> Enter the two numbers you want to add and then press the Total button. <p> Number 1: <asp:textbox id="Num1" runat=server/> + Number 2: <asp:textbox id="Num2" runat=server/> = <asp:button id="Total_Button" text="Total" OnClick="EnterBtn_Click" runat=server/> <p> <asp:label id="Total" runat=server/> </font> </form> </body> </html> |
[C#] <%@ WebService Language="C#" Class="DataService" %> using System; using System.Data; using System.Data.SqlClient; using System.Web.Services; public class DataService { [WebMethod] public DataSet GetTitleAuthors() { SqlConnection myConnection = new SqlConnection("Persist Security Info=False;Integrated Security=SSPI;server=localhost;database=pubs"); SqlDataAdapter myCommand1 = new SqlDataAdapter ("select * from Authors", myConnection); SqlDataAdapter myCommand2 = new SqlDataAdapter("select * from Titles", myConnection); DataSet ds = new DataSet(); myCommand1.Fill(ds, "Authors"); myCommand2.Fill(ds, "Titles"); return ds; } } [Visual Basic] <%@ WebService Language="VB" Class="DataService" %> Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.Services Public Class DataService <WebMethod> _ Public Function GetTitleAuthors() As DataSet Dim myConnection As New SqlConnection("Persist Security Info=False;Integrated Security=SSPI;server=localhost;database=pubs") Dim myCommand1 As New SqlDataAdapter("select * from Authors", myConnection) Dim myCommand2 As New SqlDataAdapter("select * from Titles", myConnection) Dim ds As New DataSet() myCommand1.Fill(ds, "Authors") myCommand2.Fill(ds, "Titles") Return ds End Function End Class |
[C#] <%@ WebService Language="C#" Class="Add" %> using System; using System.Web.Services; abstract public class MathService : WebService { [WebMethod] abstract public float CalculateTotal(float a, float b); } public class Add : MathService { [WebMethod] override public float CalculateTotal(float a, float b) { return a + b; } } public class Subtract : MathService { [WebMethod] override public float CalculateTotal(float a, float b) { return a - b; } } public class Multiply : MathService { [WebMethod] override public float CalculateTotal(float a, float b) { return a * b; } } public class Divide : MathService { [WebMethod] override public float CalculateTotal(float a, float b) { if (b==0) return -1; else return a / b; } } [Visual Basic] <%@ WebService Language="VB" Class="Add" %> Imports System Imports System.Web.Services MustInherit Public Class MathService : Inherits WebService <WebMethod> _ Public MustOverride Function CalculateTotal(a As Single, _ b As Single) As Single End Class Public Class Add : Inherits MathService <WebMethod> Public Overrides Function CalculateTotal(a As Single, b As Single) As Single Return a + b End Function End Class Public Class Subtract : Inherits MathService <WebMethod> Public Overrides Function CalculateTotal(a As Single, b As Single) As Single Return a - b End Function End Class Public Class Multiply : Inherits MathService <WebMethod> Public Overrides Function CalculateTotal(a As Single, b As Single) As Single Return a * b End Function End Class Public Class Divide : Inherits MathService <WebMethod> Public Overrides Function CalculateTotal(a As Single, b As Single) As Single If b = 0 Then Return - 1 Else Return a / b End If End Function End Class |
<%@ OutputCache Duration="60" %> |
[C#] <%@ Page Language="C#" %> <%@ Import Namespace="System.Net" %> <%@ OutputCache Duration="60" VaryByParam="none" %> <html> <script language="C#" runat="server"> void EnterBtn_Click(Object Src, EventArgs e) { MyMath.Math math = new MyMath.Math(); // Call the XML Web service. float total = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text)); // Display the results in a Label control. Total.Text = "Total: " + total.ToString(); } </script> <body> <form action="MathClient.aspx" runat=server> <font face="Verdana"> Enter the two numbers you want to add and press the Total button. <p> Number 1: <asp:textbox id="Num1" runat=server/> + Number 2: <asp:textbox id="Num2" runat=server/> = <asp:button id="Total_Button" text="Total" OnClick="EnterBtn_Click" runat=server/> <p> <asp:label id="Total" runat=server/> </font> </form> </body> </html> [Visual Basic] <%@ Page Language="VB" %> <%@ Import Namespace="System.Net" %> <%@ OutputCache Duration="60" VaryByParam="none" %> <html> <script language="VB" runat="server"> Sub EnterBtn_Click(Src As Object, e As EventArgs) Dim math As New MyMath.Math() ' Call the XML Web service. Dim addtotal As Single = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text)) ' Display the results in a Label control. Total.Text = "Total: " & addtotal.ToString() End Sub </script> <body> <form action="MathClient.aspx" runat=server> <font face="Verdana"> Enter the two numbers you want to add and press the Total button. <p> Number 1: <asp:textbox id="Num1" runat=server/> + Number 2: <asp:textbox id="Num2" runat=server/> = <asp:button id="Total_Button" text="Total" OnClick="EnterBtn_Click" runat=server/> <p> <asp:label id="Total" runat=server/> </font> </form> </body> </html> |
[C#] <%@ WebService Language="C#" Class="MathService" %> using System; using System.Web.Services; public class MathService : WebService { [WebMethod(CacheDuration=60)] public float Add(float a, float b) { return a + b; } [WebMethod(CacheDuration=60)] public float Subtract(float a, float b) { return a - b; } [WebMethod(CacheDuration=60)] public float Multiply(float a, float b) { return a * b; } [WebMethod(CacheDuration=60)] public float Divide(float a, float b) { if (b==0) return -1; return a / b; } } [Visual Basic] <%@ WebService Language="VB" Class="MathService" %> Imports System Imports System.Web.Services Public Class MathService Inherits WebService <WebMethod(CacheDuration := 60)> _ Public Function Add(a As Single, b As Single) As Single Return a + b End Function <WebMethod(CacheDuration := 60)> _ Public Function Subtract(a As Single, b As Single) As Single Return a - b End Function <WebMethod(CacheDuration := 60)> _ Public Function Multiply(a As Single, b As Single) As Single Return a * b End Function <WebMethod(CacheDuration := 60)> _ Public Function Divide(a As Single, b As Single) As Single If b = 0 Then Return - 1 End If Return a / b End Function End Class |