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

Discussion in 'ASP .Net' started by davidjgonzalez@gmail.com, Mar 10, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

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


    <> wrote in message
    news:...
    >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
    >
    Marina Levit [MVP], Mar 10, 2006
    #2
    1. Advertising

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


    "" 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
    >
    >
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Mar 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo
    Replies:
    1
    Views:
    504
    Scott Allen
    Jan 7, 2005
  2. Oliver Wong
    Replies:
    14
    Views:
    1,585
    Chris Uppal
    Jun 13, 2006
  3. lightning
    Replies:
    4
    Views:
    890
    Daniel Pitts
    Oct 30, 2008
  4. rantingrick
    Replies:
    44
    Views:
    1,165
    Peter Pearson
    Jul 13, 2010
  5. Kenneth McDonald
    Replies:
    5
    Views:
    299
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page