'WFC Service Client Calls Instancing and concurrency

Thanks in advance for your help. I read several articles about concurrency, Instancing and thread safety, but I confess that I still have doubts. In fact, the information in the articles is sometimes contradictory.

I have a simple WFC service that, receives a date period (StartDate and EndDate). The service has to search for files that contain a date in their name within the period defined by StartDate and EndDate. The founded files will then be Zipped and Uploaded to a Server.

After many tests I never noticed any problem with the service's operation. But before using the service in a production environment, I need to make sure that the service code is secure, in order to ensure that multiple simultaneous requests from clients don't affect the data integrity of other requests.

I posted a code snippet, and I have added comments/questions to the code.

Please note that I've set the service Instancing To PerCall. As I have noticed in microsoft documentation "in PerCall instancing, concurrency is not relevant, because each message is processed by a new service instance.". But each service instance is thread safe by it self? In other words, each client call to the service cannot change the data of other calls?

King Regards. J.Campos

' - - - - - - - - - - - - - - -  WFC Service  Contract - - - - - - - - - - - - - - - 
<ServiceContract()>
Public Interface IMyReports
    <OperationContract(IsOneWay:=True)>
    Sub SvcRequest(ByVal ClientID as integer, ByVal startDate as string, ByVal EndDate)
End Interface

' - - - - - - - - - - - - - - -  WFC Service - - - - - - - - - - - - - - - 

<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerCall)>
Public Class SvcDoRequest
    Implements IMyReports

    '??? These Private members can be changed by another Service Call?
    Private Dat1 as string=""
    Private Dat2 as string=""
    Private SearchFolder as string=""

    Public Sub SvcRequest(StartDate as string, EndDate as String) Implements IMyReports.SvcRequest
        SearchFolder= "c:\SearchFolder\" 
        Dat1 as string=StarDate 
        Dat2 as string=EndDate  
      
        Dim ListOfFiles as new List(of String)  
      
       'Recursive File Search 
       '??? Arguments passed byRef. Can the Arguments be Changed by another Service Call?
      
        Call FGetFiles(SearchFolder, ListOfFiles)
        
        Dim Result as integer=0  
        If ListOfFiles.Count>0  
            Dim ZipFileName as string="c:\MyZipFile.Zip" 
            Dim ErrMsg as string=""

            ' External Library to Create a ZIP File containing ListOfFiles()
            '??? ErrMsg is passed byRef in order to return a possible error message. 
            '??? Can ErrMsg be Changed by another Service Call?

            Dim ClZip As New  MyZipLibrary.ZipClass
            If ClZip.FCreateZip(ListOfFiles, ZipFileName, ErrMsg)=False Then
               Call WriteToLog(ErrMsg)
           Result=-1
        Else
           Result=1             
        End if
    End if
     
    ' Upload ZipFile 
    '           
    End Sub

    Private Function FGetFiles(ByRef Folder As String, ByRef LFiles As List(Of String)) as boolean 
    
        '??? is this recursive function safe? Byref args Folder,LFiles can be changed by another Call?

        For Each File1 As String In Directory.GetFiles(Folder)
            Dim FileInfo1 As New FileInfo(File1)
            Dim FileDate  As String = FileInfo1.Name.Substring(0,8)       
             If FileDate >= Dat1 And FileDate <= Dat2 Then
                 LFiles.Add(FileInfo1.FullName)
            End If
        Next
        For Each Dir1 As String In Directory.GetDirectories(Folder)
            Call FGetFiles(Dir1, LFiles)
        Next
        Return True
    End Function
End Class

'- - - - - - - - - - - - - - - - - - - - - - - - -  ZIP Library - - - - - - - - - - - 
Public Class MyZipLibrary
    Public Function FCreateZip(byval ListOfFiles as List(of String), 
                               Byval ZipFileName as string, ByRef ErrMsg as string) as Boolean    
        If Not CreateZipFile()
            'Byref Argument ErrMsg. can be changed by another client Call?                         
            ErrMsg="Unable To Create ZipFile"
            Return false
        Else
            Return True
        End if
    End function
End Class


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source