"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" <****@****.com> 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
|