473,809 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remoting for shared access


As far as I can tell, there is no way in a Web service, per se, to have
a truly shared object or resource such as a file...one that I can manage
multiple updates on with a mutex for both reading and writing.

Therefore, I think I should use a Remoted service that manages calls to
the file, with a mutex. I would then call the Remoted service from the
web service calls.

Thoughts?
Nov 16 '05 #1
9 1390
John,

I don't know if this is the best thing to do. Considering the potential
volume for accessing this, a mutex would be a performance killer.

If this is not an issue, then I don't see why you can't use a mutex in a
web service. You just should make sure that you use a named mutex? I mean,
what else would stop you from using that?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...

As far as I can tell, there is no way in a Web service, per se, to have
a truly shared object or resource such as a file...one that I can manage
multiple updates on with a mutex for both reading and writing.

Therefore, I think I should use a Remoted service that manages calls to
the file, with a mutex. I would then call the Remoted service from the
web service calls.

Thoughts?

Nov 16 '05 #2
Nicholas Paldino [.NET/C# MVP] wrote:
John,

I don't know if this is the best thing to do. Considering the potential
volume for accessing this, a mutex would be a performance killer.

If this is not an issue, then I don't see why you can't use a mutex in a
web service. You just should make sure that you use a named mutex? I mean,
what else would stop you from using that?


I understand how to set up a mutex on a file, but how do I create say a
global object, such as file, that all instances of the web service can
access without collisions ?
Nov 16 '05 #3
John,

You would create a static property in that case. As long as they are in
the same app domain (and they should be), they should all hit the same
instance.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...
Nicholas Paldino [.NET/C# MVP] wrote:
John,

I don't know if this is the best thing to do. Considering the
potential
volume for accessing this, a mutex would be a performance killer.

If this is not an issue, then I don't see why you can't use a mutex
in a
web service. You just should make sure that you use a named mutex? I
mean,
what else would stop you from using that?


I understand how to set up a mutex on a file, but how do I create say a
global object, such as file, that all instances of the web service can
access without collisions ?

Nov 16 '05 #4
Nicholas Paldino [.NET/C# MVP] wrote:
John,

You would create a static property in that case. As long as they are in
the same app domain (and they should be), they should all hit the same
instance.


Sweet.

So I could define a file object as a static property of the web service
class.

Then I could restict access to it with a named mutex ( would the mutex
be a static property as well ? ) so that multiple calls to the shared
resource would be managed.

Right ?


Nov 16 '05 #5
Nicholas Paldino [.NET/C# MVP] wrote:
John,

You would create a static property in that case. As long as they are in
the same app domain (and they should be), they should all hit the same
instance.


Are you saying that all clients access the same instance of a web
service -- and its associated methods ?

I thought that each call to a web service or web method instantiated a
new copy of the class ...


Nov 16 '05 #6
As you said, every call to a web service is made on its own instance of the
WebService class. But Nicholas has recommended you use a static field, which
is shared by all instances of the web service. So, you would just create a
static instance and use lock() to ensure thread-safe access to it.

Ken

"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...
Nicholas Paldino [.NET/C# MVP] wrote:
John,

You would create a static property in that case. As long as they are in the same app domain (and they should be), they should all hit the same
instance.


Are you saying that all clients access the same instance of a web
service -- and its associated methods ?

I thought that each call to a web service or web method instantiated a
new copy of the class ...

Nov 16 '05 #7

Thanks to both you guys, especially Nick.

Here is my code. I ran it with 3 clients calling the service in a loop
posting 1000 records each.

Before I put the .WriteLine method inside the mutex it would skip lines
or else write two numbers next to each other. Before I put the
increment of Register in the mutex it would skip or update to the same
number 2 or 3 times. With both inside the Mutex, it seems to work ok,
but I am going to load test further...

public class Service1 : System.Web.Serv ices.WebService
{

public static int Register=5;
public static StreamWriter sw;
public static Mutex mut = new Mutex();

public Service1()
{
InitializeCompo nent();
}

[WebMethod]
public int Add1()
{
mut.WaitOne();
Register++;
sw.WriteLine(Re gister);
mut.ReleaseMute x();
return Register;
}

[WebMethod]
public void closeLog()
{
sw.Close();
}

[WebMethod]
public void openLog()
{
sw = new
StreamWriter("C :\\shareadd\\re cord.txt");
sw.AutoFlush=tr ue;
}
}
Ken Kolda wrote:
As you said, every call to a web service is made on its own instance of the
WebService class. But Nicholas has recommended you use a static field, which
is shared by all instances of the web service. So, you would just create a
static instance and use lock() to ensure thread-safe access to it.

Ken

"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...
Nicholas Paldino [.NET/C# MVP] wrote:
John,

You would create a static property in that case. As long as they
are in
the same app domain (and they should be), they should all hit the same
instance.


Are you saying that all clients access the same instance of a web
service -- and its associated methods ?

I thought that each call to a web service or web method instantiated a
new copy of the class ...


Nov 16 '05 #8
Why don't you consider using MSMQ to let each client post it's records to a
queue,where asynchronously you can pick up them up and write them to a file
without the need to lock each client waiting for the Mutex. Sure this will
scale much better than a solution built around a global locking primitive.

Willy.
"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...

Thanks to both you guys, especially Nick.

Here is my code. I ran it with 3 clients calling the service in a loop
posting 1000 records each.

Before I put the .WriteLine method inside the mutex it would skip lines
or else write two numbers next to each other. Before I put the
increment of Register in the mutex it would skip or update to the same
number 2 or 3 times. With both inside the Mutex, it seems to work ok,
but I am going to load test further...

public class Service1 : System.Web.Serv ices.WebService
{

public static int Register=5;
public static StreamWriter sw;
public static Mutex mut = new Mutex();

public Service1()
{
InitializeCompo nent();
}

[WebMethod]
public int Add1()
{
mut.WaitOne();
Register++;
sw.WriteLine(Re gister);
mut.ReleaseMute x();
return Register;
}

[WebMethod]
public void closeLog()
{
sw.Close();
}

[WebMethod]
public void openLog()
{
sw = new
StreamWriter("C :\\shareadd\\re cord.txt");
sw.AutoFlush=tr ue;
}
}
Ken Kolda wrote:
As you said, every call to a web service is made on its own instance of
the
WebService class. But Nicholas has recommended you use a static field,
which
is shared by all instances of the web service. So, you would just create
a
static instance and use lock() to ensure thread-safe access to it.

Ken

"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...
Nicholas Paldino [.NET/C# MVP] wrote:

John,

You would create a static property in that case. As long as they


are in
the same app domain (and they should be), they should all hit the same
instance.

Are you saying that all clients access the same instance of a web
service -- and its associated methods ?

I thought that each call to a web service or web method instantiated a
new copy of the class ...



Nov 16 '05 #9
Willy Denoyette [MVP] wrote:

You know that's a good idea. In fact, I've already proposed another along
similiar lines for building a SOAP/XML Document databse web service.

In that case I would use SOAP messages, sent as email attachments rather
than via HTTP. I would set up an smtp listener and mail queue. Then I
would pull the email messages off the queue and extract the SOAP
attachment, and then finally, it to an XPath method which would retrieve or
modify the data within an XML document.

Instead of having a WSDL, I would create an email autoresponder that would
send the schema to the client as a SOAP attachment.

In this instance, I was simply trying to build a logging method for my web
service to write trace information to a log file and to capture Exceptions
thrown in my try/catch blocks.

Why don't you consider using MSMQ to let each client post it's records to
a queue,where asynchronously you can pick up them up and write them to a
file without the need to lock each client waiting for the Mutex. Sure this
will scale much better than a solution built around a global locking
primitive.

Willy.
"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...

Thanks to both you guys, especially Nick.

Here is my code. I ran it with 3 clients calling the service in a loop
posting 1000 records each.

Before I put the .WriteLine method inside the mutex it would skip lines
or else write two numbers next to each other. Before I put the
increment of Register in the mutex it would skip or update to the same
number 2 or 3 times. With both inside the Mutex, it seems to work ok,
but I am going to load test further...

public class Service1 : System.Web.Serv ices.WebService
{

public static int Register=5;
public static StreamWriter sw;
public static Mutex mut = new Mutex();

public Service1()
{
InitializeCompo nent();
}

[WebMethod]
public int Add1()
{
mut.WaitOne();
Register++;
sw.WriteLine(Re gister);
mut.ReleaseMute x();
return Register;
}

[WebMethod]
public void closeLog()
{
sw.Close();
}

[WebMethod]
public void openLog()
{
sw = new
StreamWriter("C :\\shareadd\\re cord.txt");
sw.AutoFlush=tr ue;
}
}
Ken Kolda wrote:
As you said, every call to a web service is made on its own instance of
the
WebService class. But Nicholas has recommended you use a static field,
which
is shared by all instances of the web service. So, you would just create
a
static instance and use lock() to ensure thread-safe access to it.

Ken

"John Bailo" <ja*****@earthl ink.net> wrote in message
news:2v******** *****@uni-berlin.de...

Nicholas Paldino [.NET/C# MVP] wrote:

>John,
>
> You would create a static property in that case. As long as they

are in

>the same app domain (and they should be), they should all hit the same
>instance .
>
>

Are you saying that all clients access the same instance of a web
service -- and its associated methods ?

I thought that each call to a web service or web method instantiated a
new copy of the class ...




--
http://www.texeme.com

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3296
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS Remoting and possible others.
10
5576
by: Michael Culley | last post by:
In vb6 it was possible to create an exe as an activeX exe and communicate between 2 apps. Now we have remoting which requires opening a tcp port to listen on, which seems kinda crappy cause another app might be using the same port. Is there an alternative way of communicating between 2 exes on the same machine? Thanks, Michael Culley
3
254
by: Patty O'Dors | last post by:
Hi I posted a similar question like this to a reply to another thread but it wasn't really relevant to that thread and I don't think anybody read it so I'm posting a new one. I'm trying to think of a use for remoting in the workplace, but can't. I want to look cool by "running commands over the network" and using "virtual server application protocols" that would make me look the don in front of bosses and probably gain me a pay rise,...
4
3120
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give it a go). What I want to do is this: Have a server instance of the program, this server instance will receive communication from client programs (as demonstrated in the AddMessage()
1
1498
by: Joe | last post by:
Question 1.) Since xml web service interface can be obtained directly by wsdl, but ..net remoting need to have the dll (interface) and then take reference to the solution, right? 2.) remoting need to be the same intranet?
6
1627
by: AMDRIT | last post by:
Hello folks, I appologize for the cross post, but I really need an answer on this: I do not think that I am seeing the whole picture here. I would like to create a windows service and a management console, using Visual Basic 2003. The windows service part, I think, is easy enough. I am more concerned with the remoting aspect of the project. Below is the general idea of my approach, please correct my where I am wrong.
2
1476
by: shaziya | last post by:
Hi there, I have created a remotig obj(dll) derived from MarshalByRefObject. I have server application, client application. If all these server exe, client exe and remorting dll are present in same directory, and then if I run server exe, then client exe, it works well. But If my server exe and remoting dll are present in other directory
4
6652
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
1
1926
by: Jeremiah Gowdy | last post by:
I am interested in deploying .NET binary remoting in a few applications, and I have learned how to do remoting via interfaces so that I don't have to share the actual class code with the client (although the interface definition has to remain in a shared DLL). Now I am trying to figure out how I can pass serialized objects without putting those objects in a shared DLL between the applications. I'm wondering if there's a way to do binary...
0
1038
by: William | last post by:
Hi I'm busy developing a .NET remoting application. Tcp remoting with a binary formatter is used. The user can specify on the client configuration whether to connect to the hosted Singleton or SingleCall objects. The application consists out of the following: - Shared assembly This contains serializable classes that are shared between the server and client applications. This also includes interfaces for the server classes. -...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.