XML web service and Hashtable problem

M

Marek

I am having a problem with Hashtable used in XML web server.
I have a WebMethod where clients get registered and added into hashtable.
Later, I call another web method which has client ID as parameter. I first
thought I was doing something wrong with keys, but now i found out the
Hashtable is empty (Count property returns 0)

Code:

[WebMethod()]
public void RegisterClient(int id)
{
if(!this.clients.ContainsKey(id))
{
this.clients.Add(id, new ClientWrapper(id));
return;
}
throw new Exception("ERROR");
}

[WebMethod()]
public void Log(string message, int clientID)
{
if(this.clients.ContainsKey(clientID))
{
ClientWrapper w = (ClientWrapper)this.clients[clientID];
w.Log(message);
return;
}
else
{
throw new Exception("Client not found while logging: " + clientID + "
Client count is " + this.clients.Count) ; //I see from here that the
Hashtable does not contain that key and Count is zero!!
}
}

I am sure that method RegisterClient is called before method Log is called.
I am not able to debug because VS says symbols were not loaded and Debug
class helps me neither because I am getting errors like "Process can not
access the file because it is used by another process" when trying to use
Debug.WriteLine()

Any help would be greatly appreciated.
 
D

Dan Bass

Marek,

So you're populating the hashtable (RegisterClient()), which is a data
member of web service class, then querying it ( Log() )?
This won't work on it's own because the object is not persistent. Web
services are meant to be a way to interface with something else, ( eg.
Database ).

You'd typically have RegisterClient add a client to a database (or file
etc), then return back the unique id, rather than expecting the caller to
provide it. Then when the Log method is called, you'd first create and
populate an instance of your ClientWrapper class by reading from your data
source (database or file), then perform your "Log".

If you need more help, perhaps provide more details into the general purpose
of the web service.

thanks.

Daniel.
 
M

Marek

Dan,
thank you very much for your reply.
I didn't know web service classes are non-persistent, I am just beginning
with web services. Thanks for clarification.

Sincerely,
Marek

Dan Bass said:
Marek,

So you're populating the hashtable (RegisterClient()), which is a data
member of web service class, then querying it ( Log() )?
This won't work on it's own because the object is not persistent. Web
services are meant to be a way to interface with something else, ( eg.
Database ).

You'd typically have RegisterClient add a client to a database (or file
etc), then return back the unique id, rather than expecting the caller to
provide it. Then when the Log method is called, you'd first create and
populate an instance of your ClientWrapper class by reading from your data
source (database or file), then perform your "Log".

If you need more help, perhaps provide more details into the general purpose
of the web service.

thanks.

Daniel.


Marek said:
I am having a problem with Hashtable used in XML web server.
I have a WebMethod where clients get registered and added into hashtable.
Later, I call another web method which has client ID as parameter. I first
thought I was doing something wrong with keys, but now i found out the
Hashtable is empty (Count property returns 0)

Code:

[WebMethod()]
public void RegisterClient(int id)
{
if(!this.clients.ContainsKey(id))
{
this.clients.Add(id, new ClientWrapper(id));
return;
}
throw new Exception("ERROR");
}

[WebMethod()]
public void Log(string message, int clientID)
{
if(this.clients.ContainsKey(clientID))
{
ClientWrapper w = (ClientWrapper)this.clients[clientID];
w.Log(message);
return;
}
else
{
throw new Exception("Client not found while logging: " + clientID + "
Client count is " + this.clients.Count) ; //I see from here that the
Hashtable does not contain that key and Count is zero!!
}
}

I am sure that method RegisterClient is called before method Log is
called.
I am not able to debug because VS says symbols were not loaded and Debug
class helps me neither because I am getting errors like "Process can not
access the file because it is used by another process" when trying to use
Debug.WriteLine()

Any help would be greatly appreciated.
 

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

Top