473,385 Members | 1,311 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,385 software developers and data experts.

Static Methods in ASP .Net web application -- Is this bad form?

I have an ASP .NET web application written in VS 2003. The web
application's UI (aspx.cs files) call static WebService accessor
methods.

Example.aspx
MyWebserviceAccessor.CallWebService("foo");

MyWebserviceAccessor.cs
public static string CallWebService(string val)
{
string result = "";
WebService1.WebService1() ws = new WebService1.WebService1();

result = ws.SomeWebMethodCall(value);
return result;
}
My concern is the CallWebService(...) is a static method and if 2 user
trigger the event that executes:
MyWebserviceAccessor.CallWebService("foo"); at the same time, I might
have some data integrity issues between users. Can anyone tell me how
ASP .NET handles static methods in ASP .NET apps? should static methods
be avoided in such applications?
Any links to authoritative texts would also be appreciated.

Thanks

Mar 10 '06 #1
2 1697
Since you are using only variables local to the method, you should be fined.
Each thread running the method, will have CallWebService instantiate its own
instances of the variables you are using, so there shouldn't be any issues.
<da************@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
I have an ASP .NET web application written in VS 2003. The web
application's UI (aspx.cs files) call static WebService accessor
methods.

Example.aspx
MyWebserviceAccessor.CallWebService("foo");

MyWebserviceAccessor.cs
public static string CallWebService(string val)
{
string result = "";
WebService1.WebService1() ws = new WebService1.WebService1();

result = ws.SomeWebMethodCall(value);
return result;
}
My concern is the CallWebService(...) is a static method and if 2 user
trigger the event that executes:
MyWebserviceAccessor.CallWebService("foo"); at the same time, I might
have some data integrity issues between users. Can anyone tell me how
ASP .NET handles static methods in ASP .NET apps? should static methods
be avoided in such applications?
Any links to authoritative texts would also be appreciated.

Thanks

Mar 10 '06 #2
Static fields are an issue, static methods are not. If you want to test this,
add a thread pause in the web service and spawn up two threads in your
ASP.NET app. Then fire both threads one after another with different
parameter values. You will see both return the correct answer.

It is fairly common to have "helper functions" as static methods.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"da************@gmail.com" wrote:
I have an ASP .NET web application written in VS 2003. The web
application's UI (aspx.cs files) call static WebService accessor
methods.

Example.aspx
MyWebserviceAccessor.CallWebService("foo");

MyWebserviceAccessor.cs
public static string CallWebService(string val)
{
string result = "";
WebService1.WebService1() ws = new WebService1.WebService1();

result = ws.SomeWebMethodCall(value);
return result;
}
My concern is the CallWebService(...) is a static method and if 2 user
trigger the event that executes:
MyWebserviceAccessor.CallWebService("foo"); at the same time, I might
have some data integrity issues between users. Can anyone tell me how
ASP .NET handles static methods in ASP .NET apps? should static methods
be avoided in such applications?
Any links to authoritative texts would also be appreciated.

Thanks

Mar 10 '06 #3

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

Similar topics

2
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the...
5
by: blah, blah, blah | last post by:
I'm developing a .Net web application and created many helper classes often using static (shared in VB.Net) methods. Do I need to use the lock (SyncLock) statement in these methods to prevent...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
15
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data...
11
by: Mark | last post by:
Is that true you can't have a static method in VB.NET? Public Static Sub Initialize() -- ??? thanks Mark
12
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
5
by: Digital Puer | last post by:
Hi, I've inherited a bunch of C code that needs to be called from a C++ framework, so I thought it would be good to put these C functions into C++ classes for better organisation. What are best...
2
by: Random | last post by:
Here's a design question I'm curious to know if anyone here has wrestled with before... I'm writing my data access methods in classes in the App_Code directory. I know that I can easily...
25
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
Hello, I'm having a discussion with my colleagues (and boss) over the use of static methods in a class. My colleagues say that static methods should be avoided whenever is possible, because...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.