Web service instance still alive?

M

Mantorok

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
 
J

John Saunders [MVP]

Mantorok said:
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.
 
M

Mantorok

John Saunders said:
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
 
J

John Saunders [MVP]

Mantorok said:
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.
 
M

Mantorok

John Saunders said:
Mantorok said:
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
 
J

John Saunders [MVP]

Mantorok said:
John Saunders said:
Mantorok said:
"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
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.
 
M

Mantorok

John Saunders said:
Mantorok said:
John Saunders said:
"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
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
 
J

John Saunders [MVP]

Mantorok said:
John Saunders said:
Mantorok said:
"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message

"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message
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.
 
M

Mantorok

John Saunders said:
Mantorok said:
John Saunders said:
"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in message

"John Saunders [MVP]" <john.saunders at trizetto.com> wrote in
message 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top