在web引用web service
using myservice;protected void btncheck_Click(object sender, EventArgs e)
    {
        string names = this.TextBox1.Text;
        myservice.MYWebService check = new myservice.MYWebService();
        //开始异步调用
       IAsyncResult result = check.Beginexituser(names,null);
        bool exits = check.Endexituser(names);        if (exits)
        {
            this.Label1.Text = "此用户已经存在";
        }
        else
        {
            this.Label1.Text = "此用户不存在";
        }
    }
1. IAsyncResult result = check.Beginexituser(names,null,“参数a");谁能告诉我这个参数a怎么设置吗?
2.在这里为什么采用  IAsyncResult result = check.Beginexituser(names,null);
        bool exits = check.Endexituser(names);异步调用?
请高手帮我解释一下?谢谢!!!

解决方案 »

  1.   

    check.Beginexituser(names,null,“参数a");你自己构造的吧?
      

  2.   


    异步不等于同步地方就是不用等待被调用方法的返回值,而可以继续执行其他代码,
    IAsyncResult result = check.Beginexituser(names,null); 
            bool exits = check.Endexituser(names);
    这样调显示不出异步的效果的,刚调用异步,然后马上就调用它的返回值的
      

  3.   

    这是我在引用web service时,那些方法是我在mywebservice.asmx中定义的方法:
    using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Data;
    using System.Data.SqlClient;
    /// <summary>
    /// MYWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class MYWebService : System.Web.Services.WebService
    {    public MYWebService()
        {        //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }    [WebMethod(Description="检查用户名是否存在指定的用户")]
        public bool exituser(string username)
        {
            bool exitname = false;//默认用户表不存在指定的用户
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Eduask_Power;User ID=sa;Persist Security Info=false");
            SqlCommand scom = new SqlCommand("select * from Ep_Student where Eps_Name=@username", conn);
            //scom.Parameters.AddWithValue("@username",username);
            scom.Parameters.Add("@username",SqlDbType.VarChar,50);
            scom.Parameters["@username"].Value = username.ToString();        conn.Open();
            SqlDataReader sdr = scom.ExecuteReader(CommandBehavior.CloseConnection);
            if (sdr.Read())
            {
                exitname = true;
            }
            sdr.Close();
            return exitname;
        }
        [WebMethod(Description = "获取服务器当前时间")]
        public DateTime getservertime()
        {
            return DateTime.Now;
        }
    }