Link to home
Start Free TrialLog in
Avatar of DJ_Back-Q
DJ_Back-Q

asked on

WebService Not Thread Safe Problem

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.
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

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 ?
Avatar of DJ_Back-Q
DJ_Back-Q

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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



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

...........................
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 ?
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...
yeah thats a BIGGIE.
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?
thats fine. 1 sec.