- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- localhost.Service t = new WindowsFormsApplication1.localhost.Service();
- MessageBox.Show(t.HelloWorld());
- MessageBox.Show("Down!");
- }
- private void button2_Click(object sender, EventArgs e)
- {
- localhost.Service t = new WindowsFormsApplication1.localhost.Service();
- t.HelloWorldCompleted += new WindowsFormsApplication1.localhost.HelloWorldCompletedEventHandler(t_HellowordCompleted);
- t.HelloWorldAsync();
- MessageBox.Show("Down!");
- }
- private void t_HellowordCompleted(object sender, localhost.HelloWorldCompletedEventArgs e)
- {
- MessageBox.Show(e.Result.ToString());
- }
- private void button3_Click(object sender, EventArgs e)
- {
- MessageBox.Show((new localhost.Service()).GetTime());
- }
- }
- }
- ---------------------webService----------------------------
- using System;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- using System.Xml.Linq;
- using System.Threading;
- [WebService(Namespace = "http://tempuri.org/")]
- [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 Service : System.Web.Services.WebService
- {
- public Service () {
- //Uncomment the following line if using designed components
- //InitializeComponent();
- }
- [WebMethod]
- public string HelloWorld() {
- Thread.Sleep(3000);
- return "Hello World";
- }
- ////缓存10秒
- [WebMethod(false,System.EnterpriseServices.TransactionOption.NotSupported,10)]
- public string GetTime()
- {
- return DateTime.Now.ToString();
- }
- }