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.
LVL 3
DJ_Back-QAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
gregoryyoungConnect With a Mentor Commented:
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
 
gregoryyoungCommented:
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
 
DJ_Back-QAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DJ_Back-QAuthor Commented:
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
 
wile_e_coyoteCommented:
<<
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
 
DJ_Back-QAuthor Commented:
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
 
gregoryyoungCommented:
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
 
DJ_Back-QAuthor Commented:
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
 
gregoryyoungCommented:
yeah thats a BIGGIE.
0
 
DJ_Back-QAuthor Commented:
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
 
gregoryyoungCommented:
thats fine. 1 sec.
0
All Courses

From novice to tech pro — start learning today.