Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all out there!
I have a web service that is querying data from the database and the response need to look like this:

<GetScanBatchResultResult>
<SessionID>string</SessionID>
<Result>int</Result>
<ErrorCode>int</ErrorCode>
<Message>string</Message>
<ScanData>
<ScanResult>
   <Itemid>int</Itemid>
   <MICR>string</MICR>
   <FIMAGE>string</FIMAGE>
   <BBIMAGE>string</BIMAGE>
   <UIMAGE>string</UIMAGE>
</ScanResult>
<ScanResult>
   <Itemid>int</Itemid>
   <MICR>string</MICR>
   <FIMAGE>string</FIMAGE>
   <BIMAGE>string</BIMAGE>
   <UIMAGE>string</UIMAGE>
</ScanResult>
</ScanData>
</GetScanBatchResultResult>


However, I only managed to get it like this:

<BMScanResponseBatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:birger:bom:CHESS">
<SessionID>6</SessionID>
<Result>1</Result>
<ErrorCode>0</ErrorCode>
<Message>SUCCESS</Message>
<ScanData>
   <ItemId>1</ItemId>
   <MICR>46453819 11 03 300000001911 01 9</MICR>
   <FIMAGE></FIMAGE>
   <BIMAGE></BIMAGE>
   <UIMAGE/>
</ScanData>
</BMScanResponseBatch>


I only get the last value in the database as result.
Can anybody please help?

What I have tried:

Here is my code:

Public Class BMScanResponseBatch
    Public Property SessionID As String
    Public Property Result As Integer
    Public Property ErrorCode As Integer
    Public Property Message As String
    Public Property ScanData As New ScanResult
End Class


Public Class ScanResult
    Public Property ItemId As Integer
    Public Property MICR As String
    Public Property FIMAGE As String
    Public Property BIMAGE As String
    Public Property UIMAGE As String
End Class


Service.asmx

Dim response As New BMScanResponseBatch

If reader.HasRows() Then
                ItemID = 0

                response.SessionID = sessionID
                response.Result = 1
                response.ErrorCode = 0
                response.Message = "SUCCESS"

                While reader.Read()
                    response.ScanData.ItemId = ItemID
                    response.ScanData.MICR = Replace(reader.Item("MICR").ToString(), ";", " ")
                    response.ScanData.FIMAGE = reader.Item("FrontImage").ToString()
                    response.ScanData.BIMAGE = reader.Item("BackImage").ToString()
                    response.ScanData.UIMAGE = ""

                    ItemID += 1
                End While
            End If
Posted
Updated 28-Dec-22 11:41am
v2

1 solution

Hi,

In the class BMScanResponseBatch you only have a single variable for ScanResult.
you need a list instead, something like that:
Public Class BMScanResponseBatch
    Public Property SessionID As String
    Public Property Result As Integer
    Public Property ErrorCode As Integer
    Public Property Message As String
    Public Property ScanData As New List(Of ScanResult)
End Class


Also in your webservice method reads all the entries to the ends and constantly updates your property. Instead you need to add each value to the list.
Something like that:

If reader.HasRows() Then
    ItemID = 0

    response.SessionID = SessionId
    response.Result = 1
    response.ErrorCode = 0
    response.Message = "SUCCESS"

    While reader.Read()
        response.ScanData.Add(
            New ScanResult With {
                .ItemId = ItemID,
                .MICR = Replace(reader.Item("MICR").ToString(), ";", " "),
                .FIMAGE = reader.Item("FrontImage").ToString(),
                .BIMAGE = reader.Item("BackImage").ToString(),
                .ScanData.UIMAGE = ""})

        ItemID += 1
    End While
End If
 
Share this answer
 
Comments
Dhanish Balloo 2021 28-Dec-22 17:57pm    
@Valery Possoz,

thank you soooooooooooooooooooooooooo much.
It worked like a charm.

Regards,
Dhanish

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900