Solved

WebService Not Thread Safe Problem

Posted on 2004-08-12
12
419 Views
Last Modified: 2008-01-16
I have about 30 client applications located all over Canada and United States.

The client written in VB .NET accesses a .NET WebService. It creates object from the Proxy of the WebService, fills them with values, then send them the WebService through a web method.

In this web method, the WebService enters the data into the database.

The problem occurs when to people calls that web method at the same time. The values in the object passed to the web method gets mixed. Caller A will often see data from caller B.

Everything works on SSL, and the code is pretty simple. I cannot explaining how the data can be mixed between threads.

It's not a database problem, the log files indicate that the data is erroneous even before reaching the Insert statement.

Can someone help me.
0
Comment
Question by:DJ_Back-Q
  • 5
  • 5
12 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11787940
1) did you remove the select max() I discussed the first 3 times you posted in regard to this ?
2) are you using any static/shared objects ?
0
 
LVL 3

Author Comment

by:DJ_Back-Q
ID: 11789380
1. Yes I did resolve this problem but it does not relay to my current problem.


Each of my client application creates an object from the WebService proxy class. That object is stored into a variable witch is in a static class called AppSettings.

Then let`s say my client wants to save a Sales Order. He then creates a sales order object with the help from the SalesOrder class which is stored in the proxy dll. The application then populate this object and then sends it to the WebService by calling a WebMethod. This WebMethod then inserts it into the database.

All the variables in the SalesOrder object are private.

I don`t think that because my WebService object is stored as a variable in a static class matters. Should it?

Thanks for anwering.
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 150 total points
ID: 11790039
do you use any shared/application level variables in the webservice itself ?

as for "1. Yes I did resolve this problem but it does not relay to my current problem." the behaviors you have been describing in various questionns sound exactly like the behaviors one would expect in a multi-threaded app doing MAX() ....

Can you just put up the code for the class ?
0
 
LVL 3

Author Comment

by:DJ_Back-Q
ID: 11791678
These are the classes which are filled in the client app and sent to the WebService
-----------------------------------------

Public MustInherit Class Request

    Shared _sProNum As String
    Shared _dInputDate As Date
    Shared _dRequiredDate As Date
    Shared _sProjectDesc As String
    Shared _iRevisionNum As Integer

    Public Property ...


    ...

End Class

Public Class SalesOrder
    Inherits Request

    Friend _sOrderNum As String
    Friend _sPO As String
    Friend _sEstimate As String

    Friend _bTaxIncluded As Boolean
    Friend _sTaxProvince As String
    Friend _dTaxAmmount As Double

    '--Toronto use only--
    Friend _sExpectedCommission As String
    Friend _sCommissionVariance As String
    Friend _bNonBillable As Boolean
    Friend _sChargeTo As String
    '--------------------

    Friend _bPermitNotApplicable As Boolean
    Friend _bPermitBySalesRep As Boolean
    Friend _bPermitByClient As Boolean
    Friend _bPermitByPattison As Boolean

    Friend _bElectricalHookUpRequired As Boolean
    Friend _bCustomerAppDrawing As Boolean
    Friend _bGraphicByOthers As Boolean

    Public Property ...
    ...

End Class
---------------------------------------

This is where I create my WebService object. RMSettings is a dll, and AppSettings is a static class.


Try
            RMSettings.AppSettings.myRMsrv = New RMsrv.RMsrv
            RMSettings.AppSettings.myRMsrv.Timeout = 1000 * 120

            If RMSettings.AppSettings.Cookies Is Nothing Then
                RMSettings.AppSettings.Cookies = New System.Net.CookieContainer
            End If

            RMSettings.AppSettings.myRMsrv.CookieContainer = RMSettings.AppSettings.Cookies

        Catch
            MessageBox.Show("Could not connect to the main server. Please verify your Internet connection." & Chr(10) & "If the problem persists please call the application's administrator.", "Request Manager Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Application.Exit()
            Application.DoEvents()
        End Try

---------------

Thanks alot gregoryyoung



0
 
LVL 4

Expert Comment

by:wile_e_coyote
ID: 11792595
<<
I don`t think that because my WebService object is stored as a variable in a static class matters. Should it?
>>

Are you saying that your client uses a static object to access the web service proxy or are you saying that the web service uses static objects?  If its the latter, then that's your problem.

Generally, its not a good idea to use static variables in web services.  ASP.NET instantiates a separate web service object to handle each web method call.  Any static references will be shared between all copies of the web service objects and hence will not be thread-safe.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Author Comment

by:DJ_Back-Q
ID: 11793311
Well the classes, methods and properties inside the webservice itself or not static. The only thing that is static is a class in wich the WebService object is stored. But it is static on the client so this wouldnt matter.

Public Class AppSettings

    Public Shared myRMsrv As RMsrv.RMsrv
    Public Shared Cookies As System.Net.CookieContainer

...........................
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11800533
I don't believe the issue is going to be with your skeleton classes being passed up but in your webservice itself. Previously you posted some code that contained various unafe sql statements ... what is the situation with that ?
0
 
LVL 3

Author Comment

by:DJ_Back-Q
ID: 11800704
The SQL statements were corrected and were not part of the problem.

I think the problem might be here

Public MustInherit Class Request

    Shared _sProNum As String
    Shared _dInputDate As Date
    Shared _dRequiredDate As Date
    Shared _sProjectDesc As String
    Shared _iRevisionNum As Integer

....

Every objects inherits from this base class.

I don't know why I putted these objects shared... what I wanted was freinds...
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11800706
yeah thats a BIGGIE.
0
 
LVL 3

Author Comment

by:DJ_Back-Q
ID: 11833600
gregoryyoung - Because the answer I found was inderictly helped by your tips I want to award you half the points, is that alright with you?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11834200
thats fine. 1 sec.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now