Web service instance still alive?

Discussion in 'ASP .Net Web Services' started by Mantorok, Jun 1, 2007.

  1. Mantorok

    Mantorok Guest

    Hi

    C# 2.0.

    I have an instance of a web-service assigned to a field, how would I know if
    the session has timed-out on that web-service? Is there anyway of checking
    this?

    Thanks
    Kev
    Mantorok, Jun 1, 2007
    #1
    1. Advertising

  2. "Mantorok" <> wrote in message news:465fed49@212.67.96.135...
    > Hi
    >
    > C# 2.0.
    >
    > I have an instance of a web-service assigned to a field, how would I know
    > if the session has timed-out on that web-service? Is there anyway of
    > checking this?


    When you say, "session", are you referring to session variables, or to the
    TCP/IP connection?

    If you're referring to the connection, I think the only way to know if it's
    still open is to use it.

    I think it's likely to be the same story for session variables.
    --
    John Saunders [MVP]
    John Saunders [MVP], Jun 2, 2007
    #2
    1. Advertising

  3. Mantorok

    Mantorok Guest

    "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    news:...
    > "Mantorok" <> wrote in message news:465fed49@212.67.96.135...
    >> Hi
    >>
    >> C# 2.0.
    >>
    >> I have an instance of a web-service assigned to a field, how would I know
    >> if the session has timed-out on that web-service? Is there anyway of
    >> checking this?

    >
    > When you say, "session", are you referring to session variables, or to the
    > TCP/IP connection?


    Session variables, if I don't access my web-service for 20 minutes and then
    attempt to access it I get "Object reference not set to an instance of an
    object" exception returned from the service.

    So if my session time elapses how would I know without it throwing an
    exception?

    Thanks
    Kev
    Mantorok, Jun 4, 2007
    #3
  4. "Mantorok" <> wrote in message
    news:f40jgb$8oh$...
    >
    > "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    > news:...
    >> "Mantorok" <> wrote in message
    >> news:465fed49@212.67.96.135...
    >>> Hi
    >>>
    >>> C# 2.0.
    >>>
    >>> I have an instance of a web-service assigned to a field, how would I
    >>> know if the session has timed-out on that web-service? Is there anyway
    >>> of checking this?

    >>
    >> When you say, "session", are you referring to session variables, or to
    >> the TCP/IP connection?

    >
    > Session variables, if I don't access my web-service for 20 minutes and
    > then attempt to access it I get "Object reference not set to an instance
    > of an object" exception returned from the service.
    >
    > So if my session time elapses how would I know without it throwing an
    > exception?


    You should always check to see if session variables are present before
    accessing them. I bet you're doing something like:

    string variable = Session["Variable"];
    if (variable.Length == 0) // If session expired, BOOM

    Instead, use String.IsNullOrEmpty(variable) to check. Then do something
    intelligent if you find that the session has expired.
    --
    John Saunders [MVP]
    John Saunders [MVP], Jun 4, 2007
    #4
  5. Mantorok

    Mantorok Guest

    "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    news:...
    > "Mantorok" <> wrote in message
    > news:f40jgb$8oh$...
    >>
    >> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >> news:...
    >>> "Mantorok" <> wrote in message
    >>> news:465fed49@212.67.96.135...
    >>>> Hi
    >>>>
    >>>> C# 2.0.
    >>>>
    >>>> I have an instance of a web-service assigned to a field, how would I
    >>>> know if the session has timed-out on that web-service? Is there anyway
    >>>> of checking this?
    >>>
    >>> When you say, "session", are you referring to session variables, or to
    >>> the TCP/IP connection?

    >>
    >> Session variables, if I don't access my web-service for 20 minutes and
    >> then attempt to access it I get "Object reference not set to an instance
    >> of an object" exception returned from the service.
    >>
    >> So if my session time elapses how would I know without it throwing an
    >> exception?

    >
    > You should always check to see if session variables are present before
    > accessing them. I bet you're doing something like:
    >
    > string variable = Session["Variable"];
    > if (variable.Length == 0) // If session expired, BOOM
    >
    > Instead, use String.IsNullOrEmpty(variable) to check. Then do something
    > intelligent if you find that the session has expired.


    Yes, that is what's happening.

    The problem is, the web-service is not self-initialising, it must be
    "activated" by the client before it can begin to accept certain requests,
    this is a bit of a security step to stop any tom, dick and harry from
    accessing my service and potentially obtaining sensitive data.

    This is why I need to somehow check at the client end, if it has ended I
    need to re-activate the service so that I can continue to use it.

    Thanks
    Kev
    Mantorok, Jun 4, 2007
    #5
  6. "Mantorok" <> wrote in message
    news:f412u3$i8d$...
    >
    > "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    > news:...
    >> "Mantorok" <> wrote in message
    >> news:f40jgb$8oh$...
    >>>
    >>> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >>> news:...
    >>>> "Mantorok" <> wrote in message
    >>>> news:465fed49@212.67.96.135...
    >>>>> Hi
    >>>>>
    >>>>> C# 2.0.
    >>>>>
    >>>>> I have an instance of a web-service assigned to a field, how would I
    >>>>> know if the session has timed-out on that web-service? Is there
    >>>>> anyway of checking this?
    >>>>
    >>>> When you say, "session", are you referring to session variables, or to
    >>>> the TCP/IP connection?
    >>>
    >>> Session variables, if I don't access my web-service for 20 minutes and
    >>> then attempt to access it I get "Object reference not set to an instance
    >>> of an object" exception returned from the service.
    >>>
    >>> So if my session time elapses how would I know without it throwing an
    >>> exception?

    >>
    >> You should always check to see if session variables are present before
    >> accessing them. I bet you're doing something like:
    >>
    >> string variable = Session["Variable"];
    >> if (variable.Length == 0) // If session expired, BOOM
    >>
    >> Instead, use String.IsNullOrEmpty(variable) to check. Then do something
    >> intelligent if you find that the session has expired.

    >
    > Yes, that is what's happening.
    >
    > The problem is, the web-service is not self-initialising, it must be
    > "activated" by the client before it can begin to accept certain requests,
    > this is a bit of a security step to stop any tom, dick and harry from
    > accessing my service and potentially obtaining sensitive data.
    >
    > This is why I need to somehow check at the client end, if it has ended I
    > need to re-activate the service so that I can continue to use it.


    No. Have the server detect session expiration. That is a server-side
    concept. Have the server return the client a message saying that the client
    needs to re-initialize.

    This message may be sent via a SOAP Fault element by throwing a
    SoapException. You may populate the Details property of the SoapException to
    provide the client with details about what happened.
    --
    John Saunders [MVP]
    John Saunders [MVP], Jun 4, 2007
    #6
  7. Mantorok

    Mantorok Guest

    "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    news:...
    > "Mantorok" <> wrote in message
    > news:f412u3$i8d$...
    >>
    >> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >> news:...
    >>> "Mantorok" <> wrote in message
    >>> news:f40jgb$8oh$...
    >>>>
    >>>> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >>>> news:...
    >>>>> "Mantorok" <> wrote in message
    >>>>> news:465fed49@212.67.96.135...
    >>>>>> Hi
    >>>>>>
    >>>>>> C# 2.0.
    >>>>>>
    >>>>>> I have an instance of a web-service assigned to a field, how would I
    >>>>>> know if the session has timed-out on that web-service? Is there
    >>>>>> anyway of checking this?
    >>>>>
    >>>>> When you say, "session", are you referring to session variables, or to
    >>>>> the TCP/IP connection?
    >>>>
    >>>> Session variables, if I don't access my web-service for 20 minutes and
    >>>> then attempt to access it I get "Object reference not set to an
    >>>> instance of an object" exception returned from the service.
    >>>>
    >>>> So if my session time elapses how would I know without it throwing an
    >>>> exception?
    >>>
    >>> You should always check to see if session variables are present before
    >>> accessing them. I bet you're doing something like:
    >>>
    >>> string variable = Session["Variable"];
    >>> if (variable.Length == 0) // If session expired, BOOM
    >>>
    >>> Instead, use String.IsNullOrEmpty(variable) to check. Then do something
    >>> intelligent if you find that the session has expired.

    >>
    >> Yes, that is what's happening.
    >>
    >> The problem is, the web-service is not self-initialising, it must be
    >> "activated" by the client before it can begin to accept certain requests,
    >> this is a bit of a security step to stop any tom, dick and harry from
    >> accessing my service and potentially obtaining sensitive data.
    >>
    >> This is why I need to somehow check at the client end, if it has ended I
    >> need to re-activate the service so that I can continue to use it.

    >
    > No. Have the server detect session expiration. That is a server-side
    > concept. Have the server return the client a message saying that the
    > client needs to re-initialize.
    >
    > This message may be sent via a SOAP Fault element by throwing a
    > SoapException. You may populate the Details property of the SoapException
    > to provide the client with details about what happened.


    Ah, you have a point there, I could catch the exception at the client-side
    and re-initialise for that particular fault.

    Is there anything else I need to be aware of or is it just a standard
    throw-catch scenario? Do I just check the Details property and handle
    accordingly?

    Thanks
    Kev
    Mantorok, Jun 4, 2007
    #7
  8. "Mantorok" <> wrote in message
    news:46646c47@212.67.96.135...
    >
    > "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    > news:...
    >> "Mantorok" <> wrote in message
    >> news:f412u3$i8d$...
    >>>
    >>> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >>> news:...
    >>>> "Mantorok" <> wrote in message
    >>>> news:f40jgb$8oh$...
    >>>>>
    >>>>> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >>>>> news:...
    >>>>>> "Mantorok" <> wrote in message
    >>>>>> news:465fed49@212.67.96.135...
    >>>>>>> Hi
    >>>>>>>
    >>>>>>> C# 2.0.
    >>>>>>>
    >>>>>>> I have an instance of a web-service assigned to a field, how would I
    >>>>>>> know if the session has timed-out on that web-service? Is there
    >>>>>>> anyway of checking this?
    >>>>>>
    >>>>>> When you say, "session", are you referring to session variables, or
    >>>>>> to the TCP/IP connection?
    >>>>>
    >>>>> Session variables, if I don't access my web-service for 20 minutes and
    >>>>> then attempt to access it I get "Object reference not set to an
    >>>>> instance of an object" exception returned from the service.
    >>>>>
    >>>>> So if my session time elapses how would I know without it throwing an
    >>>>> exception?
    >>>>
    >>>> You should always check to see if session variables are present before
    >>>> accessing them. I bet you're doing something like:
    >>>>
    >>>> string variable = Session["Variable"];
    >>>> if (variable.Length == 0) // If session expired, BOOM
    >>>>
    >>>> Instead, use String.IsNullOrEmpty(variable) to check. Then do something
    >>>> intelligent if you find that the session has expired.
    >>>
    >>> Yes, that is what's happening.
    >>>
    >>> The problem is, the web-service is not self-initialising, it must be
    >>> "activated" by the client before it can begin to accept certain
    >>> requests, this is a bit of a security step to stop any tom, dick and
    >>> harry from accessing my service and potentially obtaining sensitive
    >>> data.
    >>>
    >>> This is why I need to somehow check at the client end, if it has ended I
    >>> need to re-activate the service so that I can continue to use it.

    >>
    >> No. Have the server detect session expiration. That is a server-side
    >> concept. Have the server return the client a message saying that the
    >> client needs to re-initialize.
    >>
    >> This message may be sent via a SOAP Fault element by throwing a
    >> SoapException. You may populate the Details property of the SoapException
    >> to provide the client with details about what happened.

    >
    > Ah, you have a point there, I could catch the exception at the client-side
    > and re-initialise for that particular fault.
    >
    > Is there anything else I need to be aware of or is it just a standard
    > throw-catch scenario? Do I just check the Details property and handle
    > accordingly?


    The trick is that any unhandled exception thrown in your service will be
    turned into a SoapException with no details - except for a real
    SoapException. In that case, you can fill the Details property with whatever
    XML you need to tell the client what happened.
    --
    John Saunders [MVP]
    John Saunders [MVP], Jun 5, 2007
    #8
  9. Mantorok

    Mantorok Guest

    "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    news:%23k0%...
    > "Mantorok" <> wrote in message
    > news:46646c47@212.67.96.135...
    >>
    >> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >> news:...
    >>> "Mantorok" <> wrote in message
    >>> news:f412u3$i8d$...
    >>>>
    >>>> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
    >>>> news:...
    >>>>> "Mantorok" <> wrote in message
    >>>>> news:f40jgb$8oh$...
    >>>>>>
    >>>>>> "John Saunders [MVP]" <john.saunders at trizetto.com> wrote in
    >>>>>> message news:...
    >>>>>>> "Mantorok" <> wrote in message
    >>>>>>> news:465fed49@212.67.96.135...
    >>>>>>>> Hi
    >>>>>>>>
    >>>>>>>> C# 2.0.
    >>>>>>>>
    >>>>>>>> I have an instance of a web-service assigned to a field, how would
    >>>>>>>> I know if the session has timed-out on that web-service? Is there
    >>>>>>>> anyway of checking this?
    >>>>>>>
    >>>>>>> When you say, "session", are you referring to session variables, or
    >>>>>>> to the TCP/IP connection?
    >>>>>>
    >>>>>> Session variables, if I don't access my web-service for 20 minutes
    >>>>>> and then attempt to access it I get "Object reference not set to an
    >>>>>> instance of an object" exception returned from the service.
    >>>>>>
    >>>>>> So if my session time elapses how would I know without it throwing an
    >>>>>> exception?
    >>>>>
    >>>>> You should always check to see if session variables are present before
    >>>>> accessing them. I bet you're doing something like:
    >>>>>
    >>>>> string variable = Session["Variable"];
    >>>>> if (variable.Length == 0) // If session expired, BOOM
    >>>>>
    >>>>> Instead, use String.IsNullOrEmpty(variable) to check. Then do
    >>>>> something intelligent if you find that the session has expired.
    >>>>
    >>>> Yes, that is what's happening.
    >>>>
    >>>> The problem is, the web-service is not self-initialising, it must be
    >>>> "activated" by the client before it can begin to accept certain
    >>>> requests, this is a bit of a security step to stop any tom, dick and
    >>>> harry from accessing my service and potentially obtaining sensitive
    >>>> data.
    >>>>
    >>>> This is why I need to somehow check at the client end, if it has ended
    >>>> I need to re-activate the service so that I can continue to use it.
    >>>
    >>> No. Have the server detect session expiration. That is a server-side
    >>> concept. Have the server return the client a message saying that the
    >>> client needs to re-initialize.
    >>>
    >>> This message may be sent via a SOAP Fault element by throwing a
    >>> SoapException. You may populate the Details property of the
    >>> SoapException to provide the client with details about what happened.

    >>
    >> Ah, you have a point there, I could catch the exception at the
    >> client-side and re-initialise for that particular fault.
    >>
    >> Is there anything else I need to be aware of or is it just a standard
    >> throw-catch scenario? Do I just check the Details property and handle
    >> accordingly?

    >
    > The trick is that any unhandled exception thrown in your service will be
    > turned into a SoapException with no details - except for a real
    > SoapException. In that case, you can fill the Details property with
    > whatever XML you need to tell the client what happened.


    Thanks John, I've managed to sort this now by following your advice.

    Kev
    Mantorok, Jun 6, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clintonG
    Replies:
    0
    Views:
    378
    clintonG
    Jul 3, 2004
  2. Michael Ulmann

    Check if session with know id is still alive...

    Michael Ulmann, Oct 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    593
    John Saunders
    Oct 4, 2004
  3. Michael Lehn
    Replies:
    1
    Views:
    483
    tom_usenet
    Aug 31, 2004
  4. Sigfried Manner

    Linux / how to check if subprocess is still alive

    Sigfried Manner, Sep 1, 2003, in forum: C Programming
    Replies:
    7
    Views:
    799
    Irrwahn Grausewitz
    Sep 1, 2003
  5. hisan
    Replies:
    1
    Views:
    1,312
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page