将会话变量传递给Web服务以进行自动完成扩展程序

将会话变量传递给Web服务以进行自动完成扩展程序

本文介绍了将会话变量传递给Web服务以进行自动完成扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家
我已经为动态文本框的自动完成扩展程序编写了代码.现在,我想为此自动完成扩展程序Web服务传递会话变量.我不是通过aspx.cs代码调用Web服务,它是动态产生的.用户登录后,将创建我的会话.现在,我想将此会话发送到特定的自动完成扩展程序Webservice方法.请任何人帮助我.

这是我的代码

Hi, all
I have written code for autocomplete extender for dynamic textboxes. Now i want to pass a session variables for this autocomplete extender webservice. I am not calling the webservice through aspx.cs code, it is coming dynamically. While user logged in, then my Session is created. Now i Want to send this session to the particular autocomplete extender Webservice Method. Any one plz help me.

This is My code

<pre>[WebMethod ]
    public string[] GetCompletionList(string prefixText, int count)
    {
         DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        cn.ConnectionString = Connection;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;

        prefixText = "%" + prefixText + "%";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "spName";
        cmd.Parameters.AddWithValue("@iAccountId", Convert.ToInt32(
Session["iAccountId"].ToString()));
//Here iam getting Session["iAccountId"]=null
       cmd.Parameters.AddWithValue("@PrefixText", prefixText);
       try
        {
            cn.Open();
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
        }
        catch
        {
        }
        finally
        {
            cn.Close();
        }
        dt = ds.Tables[0];
        //Then return List of string(txtItems) as result
        List<string> txtItems = new List<string>();
        String dbValues;
        foreach (DataRow row in dt.Rows)
        {
            //String From DataBase(dbValues)
            dbValues = row["vcRemarks"].ToString();
            //dbValues = dbValues.ToLowerInvariant ();
            txtItems.Add(dbValues);
        }
        return txtItems.ToArray();
    }




在此先感谢

Murthy




Thanks in Advance

Murthy

推荐答案

[System.Web.Services.WebMethod(EnableSession = true)]

public string[] autoSuggestIndiv(string prefixText, int count, string contextKey)

{

//your coding

}


这篇关于将会话变量传递给Web服务以进行自动完成扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:17