这是一个WebService的简单例子,.aspx是一个Web Client,小弟想把它改成一个Windows Application的Client,不知道怎么写?另外,如果希望由这个WebService自动通报所有的Client这个WebService存储的String已经更新了,要用Polling怎么实现呢?.asmx<%@ WebService Language="C#" Class="MathService" %>using System;
using System.Web.Services;public class MathService : WebService { [WebMethod]
public float Add(float a, float b)
{
return a + b;
} [WebMethod]
public float Subtract(float a, float b)
{
return a - b;
} [WebMethod]
public float Multiply(float a, float b)
{
return a * b;
} [WebMethod]
public float Divide(float a, float b)
{
if (b==0) return -1;
return a / b;
}}
.aspx<%@ Import Namespace="MathService" %>
<html>
<script language="C#" runat="server">
float operand1 = 0;
float operand2 = 0; public void Submit_Click(Object sender, EventArgs E)
{
try
{
operand1 = float.Parse(Operand1.Text);
operand2 = float.Parse(Operand2.Text);
}
catch (Exception) { /* ignored */ } MathService service = new MathService();
switch (((Control)sender).ID)
{
case "加" : Result.Text = "<b>结果</b> = " + service.Add(operand1, operand2).ToString(); break;
case "减" : Result.Text = "<b>结果</b> = " + service.Subtract(operand1, operand2).ToString(); break;
case "乘" : Result.Text = "<b>结果</b> = " + service.Multiply(operand1, operand2).ToString(); break;
case "除" : Result.Text = "<b>结果</b> = " + service.Divide(operand1, operand2).ToString(); break;
}
}
</script><body style="font: 10.5pt 宋体"> <h4>使用简单的数学服务 </h4> <form runat="server"> <div style="padding:15,15,15,15;background-color:beige;width:300;border-color:black;border-width:1;border-style:solid"> 操作数 1:<br><asp:TextBox id="Operand1" Text="15" runat="server"/><br>
操作数 2:<br><asp:TextBox id="Operand2" Text="5" runat="server"/><p> <input type="submit" id="加" value="加" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="减" value="减" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="乘" value="乘" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="除" value="除" OnServerClick="Submit_Click" runat="server"> <p> <asp:Label id="Result" runat="server"/> </div> </form></body>
</html>
using System.Web.Services;public class MathService : WebService { [WebMethod]
public float Add(float a, float b)
{
return a + b;
} [WebMethod]
public float Subtract(float a, float b)
{
return a - b;
} [WebMethod]
public float Multiply(float a, float b)
{
return a * b;
} [WebMethod]
public float Divide(float a, float b)
{
if (b==0) return -1;
return a / b;
}}
.aspx<%@ Import Namespace="MathService" %>
<html>
<script language="C#" runat="server">
float operand1 = 0;
float operand2 = 0; public void Submit_Click(Object sender, EventArgs E)
{
try
{
operand1 = float.Parse(Operand1.Text);
operand2 = float.Parse(Operand2.Text);
}
catch (Exception) { /* ignored */ } MathService service = new MathService();
switch (((Control)sender).ID)
{
case "加" : Result.Text = "<b>结果</b> = " + service.Add(operand1, operand2).ToString(); break;
case "减" : Result.Text = "<b>结果</b> = " + service.Subtract(operand1, operand2).ToString(); break;
case "乘" : Result.Text = "<b>结果</b> = " + service.Multiply(operand1, operand2).ToString(); break;
case "除" : Result.Text = "<b>结果</b> = " + service.Divide(operand1, operand2).ToString(); break;
}
}
</script><body style="font: 10.5pt 宋体"> <h4>使用简单的数学服务 </h4> <form runat="server"> <div style="padding:15,15,15,15;background-color:beige;width:300;border-color:black;border-width:1;border-style:solid"> 操作数 1:<br><asp:TextBox id="Operand1" Text="15" runat="server"/><br>
操作数 2:<br><asp:TextBox id="Operand2" Text="5" runat="server"/><p> <input type="submit" id="加" value="加" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="减" value="减" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="乘" value="乘" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="除" value="除" OnServerClick="Submit_Click" runat="server"> <p> <asp:Label id="Result" runat="server"/> </div> </form></body>
</html>
解决方案 »
- 求助!c#,3D 图片随鼠标移动
- 大家好,我在c#屏幕上打了几个字,然后响应鼠标事件,修改文字的背景,如果窗口全部刷新会闪烁,能不能只刷新一部分,谢谢各位
- 怎么使鼠标离开text控件时触发事件?在线等
- asp.net大文件上传,有什么好的组件介绍一下
- 如何察看执行一段代码需要的处理器时间和内存?
- 求教!
- 如何实现下载一个文件夹下的几个文件?
- 服务程序怎么取得当前运行的目录
- 100分求vs.net 2003(注意要2003版的)中文架构版下载!!!!
- 奇怪的需求,大家看看能做到不?关于非托管DLL
- 常规下两个工程互相引用是不能的,但是我拿到一套程序,却可以互相引用
- 散分200!vc在线正在进行网站压力测试,请大家帮忙登录论坛并保持链接,多谢大家!!!! 支持者有分!!!
.aspx<%@ Import Namespace="MathService" %>
<html>
<script language="C#" runat="server">
float operand1 = 0;
float operand2 = 0; public void Submit_Click(Object sender, EventArgs E)
{
try
{
operand1 = float.Parse(Operand1.Text);
operand2 = float.Parse(Operand2.Text);
}
catch (Exception) { /* ignored */ } MathService service = new MathService();
switch (((Control)sender).ID)
{
case "加" : Result.Text = "<b>结果</b> = " + service.Add(operand1, operand2).ToString(); break;
case "减" : Result.Text = "<b>结果</b> = " + service.Subtract(operand1, operand2).ToString(); break;
case "乘" : Result.Text = "<b>结果</b> = " + service.Multiply(operand1, operand2).ToString(); break;
case "除" : Result.Text = "<b>结果</b> = " + service.Divide(operand1, operand2).ToString(); break;
}
}
</script><body style="font: 10.5pt 宋体"> <h4>使用简单的数学服务 </h4> <form runat="server"> <div style="padding:15,15,15,15;background-color:beige;width:300;border-color:black;border-width:1;border-style:solid"> 操作数 1:<br><asp:TextBox id="Operand1" Text="15" runat="server"/><br>
操作数 2:<br><asp:TextBox id="Operand2" Text="5" runat="server"/><p> <input type="submit" id="加" value="加" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="减" value="减" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="乘" value="乘" OnServerClick="Submit_Click" runat="server">
<input type="submit" id="除" value="除" OnServerClick="Submit_Click" runat="server"> <p> <asp:Label id="Result" runat="server"/> </div> </form></body>
</html>
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label1; private MathService1 service= new MathService1();
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(48, 32);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(136, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "Operand1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(48, 88);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(136, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "Operand2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 2;
this.button1.Text = "Plus";
//
// button2
//
this.button2.Location = new System.Drawing.Point(144, 136);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 3;
this.button2.Text = "Subtract";
//
// button3
//
this.button3.Location = new System.Drawing.Point(48, 168);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(72, 24);
this.button3.TabIndex = 4;
this.button3.Text = "Mutilply";
//
// button4
//
this.button4.Location = new System.Drawing.Point(144, 168);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(72, 24);
this.button4.TabIndex = 5;
this.button4.Text = "Divide";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 208);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 32);
this.label1.TabIndex = 6;
this.label1.Text = "Result";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label1);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public void Submit_Click(object sender, EventArgs E)
{
float operand1 = 0;
float operand2 = 0;
try
{
operand1 = float.Parse(textBox1.Text);
operand2 = float.Parse(textBox2.Text);
switch (((Control)sender).Text)
{
case "button1.Text" : label1.Text = "Result " + service.Add(operand1, operand2).ToString();
break;
case "subtract" : label1.Text = "Result " + service.Subtract(operand1, operand2).ToString();
break;
case "mutiply" : label1.Text = "Result " + service.Multiply(operand1, operand2).ToString();
break;
case "divide" : label1.Text = "Result " + service.Divide(operand1, operand2).ToString();
break;
}
}
catch (Exception) { /* ignored */ }
}
}
}