473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 21 '05 #1
9 2089
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.com

"John Bailo" <ja*****@earthlink.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 21 '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 21 '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.com

"John Bailo" <ja*****@earthlink.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 21 '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 21 '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 21 '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*****@earthlink.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 21 '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.Services.WebService
{

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

public Service1()
{
InitializeComponent();
}

[WebMethod]
public int Add1()
{
mut.WaitOne();
Register++;
sw.WriteLine(Register);
mut.ReleaseMutex();
return Register;
}

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

[WebMethod]
public void openLog()
{
sw = new
StreamWriter("C:\\shareadd\\record.txt");
sw.AutoFlush=true;
}
}
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*****@earthlink.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 21 '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*****@earthlink.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.Services.WebService
{

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

public Service1()
{
InitializeComponent();
}

[WebMethod]
public int Add1()
{
mut.WaitOne();
Register++;
sw.WriteLine(Register);
mut.ReleaseMutex();
return Register;
}

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

[WebMethod]
public void openLog()
{
sw = new
StreamWriter("C:\\shareadd\\record.txt");
sw.AutoFlush=true;
}
}
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*****@earthlink.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 21 '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*****@earthlink.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.Services.WebService
{

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

public Service1()
{
InitializeComponent();
}

[WebMethod]
public int Add1()
{
mut.WaitOne();
Register++;
sw.WriteLine(Register);
mut.ReleaseMutex();
return Register;
}

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

[WebMethod]
public void openLog()
{
sw = new
StreamWriter("C:\\shareadd\\record.txt");
sw.AutoFlush=true;
}
}
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*****@earthlink.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 21 '05 #10

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

Similar topics

0
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...
10
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...
3
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...
4
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...
1
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...
6
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...
2
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...
4
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
1
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.