何时在Web服务中使用EnableSession = true,即[WebMethod(EnableSession = true)] [英] when to use EnableSession = true i.e. [WebMethod(EnableSession = true)] in Web Service

查看:92
本文介绍了何时在Web服务中使用EnableSession = true,即[WebMethod(EnableSession = true)]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ajax的CascadingDropDown控件绑定DDL国家/地区并根据国家/地区的选择绑定另一个DDL状态。

在Web服务中是: -

[WebMethod]

public CascadingDropDownNameValue [] GetCountryCDD()

{

List< string> names = new List< string>();

string str = @select * from(select 0 tID,'< - Select - >'Name union SELECT tID,Name FROM M_Country )按名称命令;

DataTable dt = new DataTable();

dt = SQL_DBCS.ExecuteDataTable(str);



列表< cascadingdropdownnamevalue> CountryDet = new List< cascadingdropdownnamevalue>();

foreach(dt.Rows中的DataRow dtrow)

{

string EcCountryId = dtrow [ tID]。ToString();

string EcCountry = dtrow [Name]。ToString();

CountryDet.Add(new CascadingDropDownNameValue(EcCountry,EcCountryId)) ;

}

返回CountryDet.ToArray();



}



AND





[WebMethod]

public CascadingDropDownNameValue [] GetStateCDD( string knownCategoryValues,string category)

{



String countryID;

StringDictionary CountryDic = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString (knownCategoryValues);

countryID = Convert.ToString(CountryDic [C]);



string str = @select * from (选择0 tID,'< - -Select - >'Name union SELECT tID,Name FROM M_State WHERE CountryID =+ countryID +)AS T ORDER BY Name;

DataTable dt = new DataTable();

dt = SQL_DBCS.ExecuteDataTable(str);



List< cascadingdropdownnamevalue> Statedetails = new List< cascadingdropdownnamevalue>();

foreach(dt.Rows中的DataRow dtrow)

{

string EcStateId = dtrow [ tID]。ToString();

string EcState = dtrow [Name]。ToString();

Statedetails.Add(new CascadingDropDownNameValue(EcState,EcStateId)) ;

}

返回Statedetails.ToArray();

}



这是按照需要工作的。但我想知道何时使用EnableSession = true。不使用它有什么害处。

I am using CascadingDropDown control of Ajax to bind DDL country and depending on selection of country bind another DDL State.
In Web Services is:-
[WebMethod]
public CascadingDropDownNameValue[] GetCountryCDD()
{
List<string> names = new List<string>();
string str = @"select * from (select 0 tID, '<--Select-->' Name union SELECT tID, Name FROM M_Country) AS T ORDER BY Name";
DataTable dt = new DataTable();
dt = SQL_DBCS.ExecuteDataTable(str);

List<cascadingdropdownnamevalue> CountryDet = new List<cascadingdropdownnamevalue>();
foreach (DataRow dtrow in dt.Rows)
{
string EcCountryId = dtrow["tID"].ToString();
string EcCountry = dtrow["Name"].ToString();
CountryDet.Add(new CascadingDropDownNameValue(EcCountry, EcCountryId));
}
return CountryDet.ToArray();

}

AND


[WebMethod]
public CascadingDropDownNameValue[] GetStateCDD(string knownCategoryValues, string category)
{

String countryID;
StringDictionary CountryDic = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
countryID = Convert.ToString(CountryDic["C"]);

string str = @"select * from (select 0 tID, '<--Select-->' Name union SELECT tID, Name FROM M_State WHERE CountryID=" + countryID + ") AS T ORDER BY Name";
DataTable dt = new DataTable();
dt = SQL_DBCS.ExecuteDataTable(str);

List<cascadingdropdownnamevalue> Statedetails = new List<cascadingdropdownnamevalue>();
foreach (DataRow dtrow in dt.Rows)
{
string EcStateId = dtrow["tID"].ToString();
string EcState = dtrow["Name"].ToString();
Statedetails.Add(new CascadingDropDownNameValue(EcState, EcStateId));
}
return Statedetails.ToArray();
}

This is working as desired. But I want to know when to use EnableSession = true. what is harm in not using it.

推荐答案

如果您的网络方法不需要会话,那么您不需要设置它。当EnableSession为true时,您的webmethod在网页所在的Session中运行,因此可以访问\更新会话值。
If your web method doesn't need the Session then you don't need to set it. When EnableSession is true your webmethod runs in the same Session that the web pages do, so can access\update Session values.


这篇关于何时在Web服务中使用EnableSession = true,即[WebMethod(EnableSession = true)]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆