Webservice session problem

Rate It (2)

Last post 07-21-2008 5:05 PM by semorad. 14 replies.

Sort Posts:

  • Webservice session problem

    04-05-2006, 4:29 AM
    • Loading...
    • tumatu
    • Joined on 04-05-2006, 8:22 AM
    • Posts 5

    When i set session variable in aspx page , I couldnt access it in webservice.It returns null value,I think, Microsoft.Web.Services.ScriptHandlerFactory kills session variables.How can overcome this problem?

    Thanks;

  • Re: Webservice session problem

    04-05-2006, 3:20 PM
    • Loading...
    • davidebb
    • Joined on 06-11-2002, 12:31 PM
    • Redmond, WA
    • Posts 915
    • AspNetTeam

    For this to work, you need to mark your web method appropriately.  e.g.

    [WebMethod(EnableSession=true)]
    ...

    David

  • Re: Webservice session problem

    04-06-2006, 1:22 AM
    • Loading...
    • tumatu
    • Joined on 04-05-2006, 8:22 AM
    • Posts 5

    It doesnt work.I want to reach it in select method of Listview's webservice.But it returns null.

    In aspx page ;

     protected void Page_Load(object sender, EventArgs e){
         Session["test"] = "hello";
       }

    In webservice ;

        [DataObjectMethod(DataObjectMethodType.Select)]
        [WebMethod(EnableSession = true)]
        public BLL.Collections.ImkbAtlas[] SelectImkbRows()
        {
            string sessionString = (string)Session["test"];
            return MainPageWebService.Data3.ToArray();
        }

     

  • Re: Webservice session problem

    04-06-2006, 2:03 PM
    • Loading...
    • davidebb
    • Joined on 06-11-2002, 12:31 PM
    • Redmond, WA
    • Posts 915
    • AspNetTeam

    This is different: your method is not directly a Web Method, but a data method, which works differently.  Currently, there is no easy way to enable Session state in this case, but we are working on making this work in a future build.

    David

  • Re: Webservice session problem

    04-10-2006, 8:19 AM
    • Loading...
    • art.and.co
    • Joined on 04-10-2006, 12:13 PM
    • Posts 4

    I don't know if this may help. Currently I spend some time on it also. I noticed that it says "New line in constant" when I try to watch on this.Context.Request.Cookies[""ASP.NET_SessionId"] at web service data call, however, fidler shows that this cookie passed well.

    Best regards

  • Re: Webservice session problem

    04-10-2006, 4:39 PM
    • Loading...
    • davidebb
    • Joined on 06-11-2002, 12:31 PM
    • Redmond, WA
    • Posts 915
    • AspNetTeam
    Seems you have duplicate double quotes after the '[', probably causing this 'new line in constant' error.
  • Re: Webservice session problem

    04-11-2006, 1:59 AM
    • Loading...
    • art.and.co
    • Joined on 04-10-2006, 12:13 PM
    • Posts 4
    Oh, yeah, silly me. You are correct. Smile [:)]
  • Re: Webservice session problem

    04-11-2006, 10:42 AM
    • Loading...
    • tumatu
    • Joined on 04-05-2006, 8:22 AM
    • Posts 5

    It doesnt work. :( I cant access cookies that created in aspx page from DataService.Can you send sample code part?

    Thanks.... 

  • Re: Webservice session problem

    04-11-2006, 3:38 PM
    • Loading...
    • davidebb
    • Joined on 06-11-2002, 12:31 PM
    • Redmond, WA
    • Posts 915
    • AspNetTeam

    Please see my previous response:

    This is different: your method is not directly a Web Method, but a data method, which works differently.  Currently, there is no easy way to enable Session state in this case, but we are working on making this work in a future build.

    The little issue above with the missing quote is unrelated.  Sorry for the confusion.

    David

  • Re: Webservice session problem

    07-31-2006, 4:24 PM
    • Loading...
    • Joël Hébert
    • Joined on 07-20-2005, 6:07 PM
    • Ottawa Canada
    • Posts 614

    Thanks alot davidbb it works wonders for me....

     

    [

    WebMethod(EnableSession = true)]

    public String[] FindProducts(String prefixText, int count)

    {

    String text = prefixText;

    dal a = new dal();

    //return all records whose Title starts with the prefix input string

    List<String> titleArList = new List<string>();

    try

    {

    switch ((string)Session["control"]) {
    Joël Hébert

    ASP.NET Consultant
    Opulent ASP Development Inc.
    www.opulentasp.com
    Ottawa,Canada

    Click "Mark as Answer" on the posts that helped you to help future readers to get the solutions
  • Re: Webservice session problem

    10-19-2006, 12:14 PM
    • Loading...
    • gpbenoit
    • Joined on 10-19-2006, 2:13 PM
    • Atlanta, GA
    • Posts 98

    Joel,

    Did the above solution work for you and you were able to access session state by placing the (EnableSession = true) next to your WebMethod decleration?

    I have a web service method called DeleteTask(int task_key) and I am trying to figure out the best method for authenticating this web service call. I figured I could keep the user's User_Key in session state and perform a simple authentication against the User_Key in session when the DeleteTask() method is called...is this how you would authenticate a web service call?

    Thanks,
    Greg

  • Re: Webservice session problem

    10-20-2006, 3:28 AM

    If you're using forms Authentication you should just be able to use the following

    HttpContext.Current.User.Identity.IsAuthenticated

     

    which will use the FormsAutentication Cookie, hence no need for Session State.

     

    Filed under: ,
  • Re: Webservice session problem

    10-24-2006, 3:43 PM
    • Loading...
    • gpbenoit
    • Joined on 10-19-2006, 2:13 PM
    • Atlanta, GA
    • Posts 98
    If the entire web application including the web services (.asmx) require forms authentication, then that should protect my web service methods from being accessed by anonymous users...right?
  • Re: Webservice session problem

    10-25-2006, 2:36 AM
    Yep, it should do.
  • Re: Webservice session problem

    07-21-2008, 5:05 PM
    • Loading...
    • semorad
    • Joined on 07-21-2008, 4:52 PM
    • Posts 1

    Thanx!

    for that attribute, it is super in Ajax environment....

Page 1 of 1 (15 items)