locked
Calling same web serice method multiple time asynchronously RRS feed

  • Question

  • User613648415 posted
    I am passing 50 records in array to web service evry time I call it. I am using asynchronous call. After this ar.AsyncWaitHandle.WaitOne() line code doesn't work at all. While (startItemPosition <= itemCodeArrayTemp.Length) Array.Clear(ItemCodes, 0, 50) 'Preparing an array of 50 items to pass to web method If (endItemPosition < itemCodeArrayTemp.Length) Then Array.Copy(itemCodeArrayTemp, startItemPosition, ItemCodes, 0, 49) Else Array.Copy(itemCodeArrayTemp, startItemPosition, ItemCodes, 0, (itemCodeArrayTemp.Length - 1 - startItemPosition)) ReDim Preserve ItemCodes((itemCodeArrayTemp.Length - startItemPosition - 1)) End If 'All Asynchronous calls fired... ar = PIMSItems.BeginItemSupplierByItemList(ItemCodes, supplierID, GetItemSupplierByItemList.SupplierType.Vendor, Now.Date, ListOfOptions, 0, 0, GetItemSupplierByItemList.YesNo.No, Nothing, Nothing) ar.AsyncWaitHandle.WaitOne() -- Control hangs here.... 'status of an asynchronous calls is kept in as array asynchResult(i) = ar i = i + 1 ' Setting start and end postions for the next asynchronous call.. startItemPosition = endItemPosition + 1 endItemPosition = startItemPosition + 49 End While Same thing, I have simiulated in different way.. for testing purpose...This code works fine.. pls let me know what is the problem with above code... Dim items(500) As Integer Dim returnitems() As Integer Here items array is popilated with 50 codes.. Dim PIMSItems As GetItemSupplierByItemList.GetItemSupplierByItemList Dim ListOfOptions As Short() Dim ItemCodes(50) As Integer Dim i, j, k As Integer Dim SIobject As GetItemSupplierByItemList.ItemSupplierList Dim startItemPosition, endItemPosition As Integer Dim Itemcode As Integer Dim orderableItems As ArrayList Dim duplicateItems As ArrayList Dim listItem As GetItemSupplierByItemList.ItemSupplier Dim duplicateCounter As Integer Dim ar As IAsyncResult Dim NoofLoops As Double Dim ItemOrderStatus As String Dim ReturnCode As Integer Dim enterCodeFalg As Boolean Dim AsyncHandleArrayList As ArrayList PIMSItems = New GetItemSupplierByItemList.GetItemSupplierByItemList With PIMSItems ' .Url = CStr(configReader.GetValue("Publix.SeafoodOrdering.Data.SeaNetPIMSSA.GetItemSupplierByItemList.GetItemSupplierByItemList", GetType(String))) .Url = "http://publix.com/Publix.PIMSReads.Services.GetItemSupplierByItemList/GetItemSupplierByItemList/GetItemSupplierByItemList" .PreAuthenticate = True .ConnectionGroupName = "SEANet" .Credentials = System.Net.CredentialCache.DefaultCredentials .Timeout = 600000 End With ListOfOptions = New Short() {0, 1, 2} For i = 0 To 1 ar = PIMSItems.BeginItemSupplierByItemList(items, 4442, GetItemSupplierByItemList.SupplierType.Vendor, Now.Date, ListOfOptions, 0, 0, GetItemSupplierByItemList.YesNo.No, Nothing, Nothing) ar.AsyncWaitHandle.WaitOne() Next If ar.IsCompleted = True Then SIobject = PIMSItems.EndItemSupplierByItemList(ar) End If Pls let me know what is problem with first piece of code. Thanks, Lingaraj
    Saturday, March 12, 2005 4:04 PM

All replies

  • User613648415 posted
    Now WaitAll works fine. I have diferrent problem now.. take look at the below code... ListOfOptions = New Short() {0, 1, 2} NoofLoops = Math.Ceiling(itemCodeArrayTemp.Length / 50) startItemPosition = 0 endItemPosition = 49 Dim asynchResult As ArrayList asynchResult = New ArrayList AsyncHandleArrayList = New ArrayList Dim waithandles As New ArrayList Dim i As Integer While (startItemPosition < itemCodeArrayTemp.Length) Array.Clear(ItemCodes, 0, 50) 'PREPARING AN ARRAY OF 50 ITEMS TO PASS TO WEB METHOD If (endItemPosition < itemCodeArrayTemp.Length) Then Array.Copy(itemCodeArrayTemp, startItemPosition, ItemCodes, 0, 50) Else Array.Copy(itemCodeArrayTemp, startItemPosition, ItemCodes, 0, (itemCodeArrayTemp.Length - startItemPosition)) ReDim Preserve ItemCodes((itemCodeArrayTemp.Length - startItemPosition - 1)) End If 'ALL ASYNCHRONOUS CALLS FIRED... asynchResult.Add(PIMSItems.BeginItemSupplierByItemList(ItemCodes, 4442, GetItemSupplierByItemList.SupplierType.Vendor, Now.Date, ListOfOptions, 0, 0, GetItemSupplierByItemList.YesNo.No, Nothing, Nothing)) ' SETTING START AND END POSTIONS FOR THE NEXT ASYNCHRONOUS CALL.. startItemPosition = endItemPosition + 1 endItemPosition = startItemPosition + 49 End While 'WAIT FOR ALL THE SIMULTANEOUS ASYNCHRONOUS CALLS TO FINISH orderableItems = New ArrayList orderableItems.Clear() Dim duplicateCounterArray(asynchResult.Count - 1) As Integer 'FINDING DUPLICATE ITEMS AND ORDERABLE ITEMS For noofCalls = 0 To asynchResult.Count - 1 CType(asynchResult.Item(noofCalls), IAsyncResult).AsyncWaitHandle().WaitOne() 'CHECK TO SEE IF ASYNCHROUS CALL IS COMPLETED If CType(asynchResult.Item(noofCalls), IAsyncResult).IsCompleted = True Then ' TAKE THE OUTPUT OF ASYNCHRONOUS CALLS ONE BY ONE SIobject = PIMSItems.EndItemSupplierByItemList(CType(asynchResult.Item(noofCalls), IAsyncResult)) duplicateCounter = 0 For itemNo = 0 To SIobject.ItemSupplierArray.Length - 1 Itemcode = SIobject.ItemSupplierArray(itemNo).BaseDetails.ItemCode ItemOrderStatus = SIobject.ItemSupplierArray(itemNo).BaseDetails.ItemOrderStatus.Trim ReturnCode = SIobject.ItemSupplierArray(itemNo).ReturnCode enterCodeFalg = True If (SIobject.MainReturnCode = 1) AndAlso (ReturnCode = 1 OrElse ReturnCode = 2 OrElse ReturnCode = 3 OrElse ReturnCode = 4) Then enterCodeFalg = False End If 'CHECK TO SEE IF THE RESULT HAS SOME DUPLICATE DISK PACK ITEMS If enterCodeFalg = True Then If ReturnCode = 3 Then If orderableItems.Contains(Itemcode) = False Then If ItemOrderStatus = "Y" Then orderableItems.Add(SIobject.ItemSupplierArray(itemNo).BaseDetails.ItemCode.ToString + "," + SIobject.ItemSupplierArray(itemNo).BaseDetails.StandardDescription) End If Else duplicateCounter += 1 End If Else 'If ItemOrderStatus = "Y" Then orderableItems.Add(SIobject.ItemSupplierArray(itemNo).BaseDetails.ItemCode.ToString + "," + SIobject.ItemSupplierArray(itemNo).BaseDetails.StandardDescription) 'End If End If End If Next duplicateCounterArray(noofCalls) = duplicateCounter End If Next You can also see the above code. I am firing four web method calls simultanously passing different parameters in each call. After the loop when I take the output/result ( when I say endwebmethodname on proxy), I get a wrong results... I get the result of last waithandle for all the waithandles.. I saw the waihandles arraylist it contains different values for waithandles... pls let me know what is the problem... When I implement this in a loop whithout asynchronously it works fine.... pls help me..... Thanks, Lingaraj
    Monday, March 21, 2005 10:26 AM
  • User613648415 posted

    Done. No issues...

    Thanks,
    Lingaraj

     

     

     

    Tuesday, April 19, 2005 12:58 PM