Solved

WebService Not Thread Safe Problem

Posted on 2004-08-12
12
447 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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