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

D

davidjgonzalez

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
 
M

Marina Levit [MVP]

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.
 
G

Guest

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!
***************************
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top