Web Services Shared Resource/Memory

G

Grandpa Pete

How can I share resources across all users of a web service for read/write
access.

*Situation* *one*:

I want to have an in memory counter that all users of the webservice could
access. Call it g_count.

Then I create a web method called Update_g_count.

public int g_count( int incr )
{
g_count += incr;
return g_count;
}

So, how do I define g_count so it's global across all users?

*Situation* *two*:

I have an XML file that I want to load into an XmlDocument.

I want to set up a Web Method that uses XPath to find a node, and then
change the value of the InnerText.

How do I put this XmlDocument into memory so all users can update it without
collisions when they try to update the nodes?

Do I need to use a mutex ?

How can this mutex apply across all users of the web service ?

Do I put it in global.asax ?
 
G

Guest

Hi,

You can use the Application object to store the object accross web services.

public int g_count()
{
......
// Get the count
int gcount = (int) Context.Application["gcount"];

...// Process it

//Save it back
Context.Application["gcount"] = gcount ;

}


Although its not a recomended way to share such resources in read/write mode when specially in the case of web applications.

You can using the lock C# keyword to lock access to the object while you are modifying it.

--
Regards,
Saurabh Nandu
AksTech Solutions, reflecting your needs...
[ www.AksTech.com ]
[ www.MasterCSharp.com ]
 
D

Donnie Darko

You say that this is not a 'recommended' way to share resources in web
applications.

Can you suggest a recommended way?

Specifically, I want to share access to an XmlDocument across all users of
my web service. I want them to be able to query and update nodes on the
document.


Saurabh said:
Hi,

You can use the Application object to store the object accross web
services.

public int g_count()
{
.....
// Get the count
int gcount = (int) Context.Application["gcount"];

..// Process it

//Save it back
Context.Application["gcount"] = gcount ;

}


Although its not a recomended way to share such resources in read/write
mode when specially in the case of web applications.

You can using the lock C# keyword to lock access to the object while you
are modifying it.
 
D

Donnie Darko

That raises a lot of questions for me.

Just what is the potential of the XmlDocument class and XPath methods?

Are the numbers below based on fact, or just finger in the air estimates?

For example -- what is the performance of XPath on large XML documents.

For small documents, it seems lickety-split.

If an XmlDocument is implemented using a b-tree structure, then even for
very large numbers of records the speed of search should not increase by
much, right ?
 
G

Guest

hi,

XML is best when its used as a data exchange document, and not as a database as such. The reason i don't recomend using it as a database (shared amongst users) is that you end up writing a lot of locking code to ensure that when one user is updating the document others cannot write to it and things like that.

Now suppose 2 users tried to update at the same time, ones request will pass through other will fail since the document gets locked.

FOr multiple read/write the best source to store data is a database!! Its meant to help you d multiple read/writes without locking the users.



--
Regards,
Saurabh Nandu
AksTech Solutions, reflecting your needs...
[ www.AksTech.com ]
[ www.MasterCSharp.com ]



Donnie Darko said:
You say that this is not a 'recommended' way to share resources in web
applications.

Can you suggest a recommended way?

Specifically, I want to share access to an XmlDocument across all users of
my web service. I want them to be able to query and update nodes on the
document.


Saurabh said:
Hi,

You can use the Application object to store the object accross web
services.

public int g_count()
{
.....
// Get the count
int gcount = (int) Context.Application["gcount"];

..// Process it

//Save it back
Context.Application["gcount"] = gcount ;

}


Although its not a recomended way to share such resources in read/write
mode when specially in the case of web applications.

You can using the lock C# keyword to lock access to the object while you
are modifying it.

--
incognito @ http://kentpsychedelic.blogspot.com/

Man is the best computer we can put aboard a spacecraft ... and the only one
that can be mass produced with unskilled labor. -- Werner von Braun
 
G

Guy LaRouche

Saurabh Nandu wrote:

Actually, I already created a Windows service that allows multithreaded
access to an XmlDocument for simulaneous 'users' to read/write. I use the
Mutex class. I mutex is like queueing system, it takes in requests from
multiple threads or sources and let's them in one at a time, so there is no
collision.

Xml /is/ a 'data' base.

What you are referring to as a database is a Sql relational database.
Tables in a relational database are orthogonal. Each record has all the
fields of all the others, and no more.

Xml is a hierarchical database. But, it is also 'ragged'. Not all nodes
have to have the same attributes, or child nodes.

For many uses, Xml could be idea. That is why I am interested in creating
this web service.

I also feel that many web 'database' applications need only a single table
with very complicated nodes. In that case, a relational database, such as
sql server, is the *wrong* choice for web-data applications; and Xml could
be *very* useful.
 
G

Guest

Hi,

If you read my post the main reason I have stated to not go for XML as a database, is that you need to write a lot of code to get multi-threading right! Not everyone is able to write multi-threaded applications correctly...plus you loose all the other features RDBMS system provide to you like Transactions, Security, etc.

I agree with the benefits you have listed which would warrent using XML as a datasource, but for most users they tend to use it in the same format as one uses a RDBMS.

--
Regards,
Saurabh Nandu
AksTech Solutions, reflecting your needs...
[ www.AksTech.com ]
[ www.MasterCSharp.com ]
 

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