Results 1 to 21 of 21

Thread: [RESOLVED] Webservice - return multiple records from table

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Resolved [RESOLVED] Webservice - return multiple records from table

    I need to write a webservice that returns multiple rows from a table. I am familiar with return of a single object.

    I am calling a stored procedure in the webservice that populates a data table.

    I guess I need to define an object collection to be returned. Should this be an array or can I return the data table itself?

    Any input is appreciated. Thank you.
    Last edited by snufse; Aug 11th, 2011 at 10:01 AM.

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Re: Webservice - return multiple records from table

    You could use the dataset object available in ADO.Net. You could also write the dataset contents into an XML file and return that file (as a string). These are just the simpler of the ways so you can be comfortable with returning multiple rows.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Question Re: Webservice - return multiple records from table

    I was playing with returning datatable and it semms to work fine

    Code:
    - <myDataTable diffgr:id="myDataTable1" msdata:rowOrder="0"> 
    <SHKCOO>00000</SHKCOO> 
    <SHDOCO>100</SHDOCO> 
    <SHDCTO>SD</SHDCTO> 
    <SHMCU>30</SHMCU> 
    <SHAN8>4243</SHAN8> 
    <SHSHAN>4243</SHSHAN> 
    <SHPA8>0</SHPA8> 
    <SHTRDJ>112197</SHTRDJ> 
    <SHADDJ>0</SHADDJ> 
    <SHVR01 xml:space="preserve"></SHVR01> 
    <SHPTC xml:space="preserve"></SHPTC> 
    <SHAFT>Y</SHAFT> 
    </myDataTable>

    So is there a difference using a DataSet or what is the preference? Thank you.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    my personal preference would be to return a list(of) rather than the datatable. Using the datatable implies that the source is a database (it may not be) and the implementation is then also tied to the database (what if a field is added, do you want it or not? or what if a field is removed from the db?) To me it just seems a little more ideal to isolate things as much as you can. Then the calling code doesn't care what the implementation is... all it sees is the object.

    The way I'd do it is to implement a custom class and collection (that is a List(Of)), fill it, serialize it to XML, compress it, and return it. On the calling side, it would be decompressed and deserialized back into a list.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: Webservice - return multiple records from table

    Hello,

    What you say makes sense. I would like to try that approach. Is there a chance you have a reference or a code snippet that I could start working from?

    I searched for List(Of....) but could not find anything. Is this the same as using ArrayList Class?
    IList?

    Thank you.
    Last edited by snufse; Aug 11th, 2011 at 11:48 AM.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    Sadly, I do not happen to have something handy. A year ago I might have... but I've "moved on" ... :/

    basically, the idea is to create a list(Of T) ... where T is your custom class, then use XMLSerializer to serialize it to a MemoryStream and send it into an array of bytes. The WebService method would then return an array of bytes... on the client site, take the array of bytes, send it back into a new memory stream and feed that into the XMLSerializer to be deserialized back into the List(of T) object....

    Hmmm... I missed something there... the compression... umm... it goes in there somewhere, probably somewhere between the serialization and the conversion to byte array, you'll probably want to look it up. .NET does have a compression class built-in... it might be easier to initially get the process working w/o the compression, and then add it in later.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Webservice - return multiple records from table

    Hello,

    Have a look at this thread here:

    http://www.vbforums.com/showthread.php?t=655303

    It should be able to provide what you need.

    Gary

  8. #8

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Wink Re: Webservice - return multiple records from table

    Now, I am trying to use the List(OF....). It looks like it is working as I have the correct values in the ListOf objects. I am getting an error on the return in the web method where I have specified the ListOf as an Object:

    PHP Code:
    System.InvalidOperationExceptionThere was an error generating the XML document. ---> System.InvalidOperationExceptionThe type System.Collections.Generic.List`1[[GetCustomerOrderHeaders.OrderList, GetCustomerOrderHeaders, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] may not be used in this context. 
    Code:
    <WebMethod()> _
        Public Function GetCustomerRecords_ListOf(ByVal myDateFrom As DateTime) As Object  'ListOf
    
            OpenConnection()
            GetRecords(myDateFrom)
            CloseConnection()
            ListOf = GetListOf()
            Return ListOf
    
        End Function

    Code:
    Public Class OrderList
    
        Private _shkcoo As String
        Public Property SHKCOO() As String
            Get
                Return _shkcoo
            End Get
            Set(ByVal value As String)
                _shkcoo = value
            End Set
        End Property
    
        Private _shdoco As String
        Public Property SHDOCO() As Integer
            Get
                Return _SHDOCO
            End Get
            Set(ByVal value As Integer)
                _SHDOCO = value
            End Set
        End Property
    
        Public Sub New()
    
        End Sub
    
        Public Sub New(ByVal _shkcoo As String, ByVal _shdoco As String)
            SHKCOO = _shkcoo
            SHDOCO = _shdoco
        End Sub
    
    End Class

    Code:
    Public Function GetListOf() As List(Of OrderList)
    
            Dim ListOf As New List(Of OrderList)
            Dim myDataRow As DataRow
    
            For Each myDataRow In mySqlDataTable.Rows
                ListOf.Add(New OrderList(myDataRow.Item("SHKCOO").ToString, CInt(myDataRow.Item("SHDOCO"))))
            Next
    
            Return ListOf
    
        End Function
    Last edited by snufse; Aug 12th, 2011 at 10:52 AM.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    Almost....

    1) your ListOf variable needs to be defined properly in the first code snip - you don't have option strict or explicit turned on do you? tisk tisk tisk
    2) Same code snip, your WebMEthod needs to return List(Of OrderList) since that is what you're returning.
    3) This means you need a reference to the OrderList class on the calling end....

    This is why I thought serializing it to XML will help... you could define a class on the calling end that LOOKS jsut like OrderList on the server ,but could be in a different namespace (so now you don't need to have a reference to the exact same OrderList class... they just need to look the same. This would change your wbmethod return type to something other than List(Of OrderList) and would be string or an array of bytes...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Question Re: Webservice - return multiple records from table

    Hello

    I got the ListOf working doing

    Code:
    <WebMethod()> _
        Public Function GetCustomerRecords_ListOf(ByVal myDateFrom As DateTime) As List(Of OrderList)
            OpenConnection()
            GetRecords(myDateFrom)
            CloseConnection()
            List = GetListOf()
            Return List
    
        End Function
    Thank you.

    Now I am trying the "serialized approach....

    Have following:

    Code:
    <WebMethod()> _
        Public Function GetCustomerRecords_Serialized(ByVal myDateFrom As DateTime) As StreamWriter
    
            OpenConnection()
            GetRecords(myDateFrom)
            CloseConnection()
            oStmW = GetSeriaLized()
            Return oStmW
    
        End Function
    Code:
    Imports System.Xml.Serialization
    
    <XmlRoot(ElementName:="OrderHeader")> _
    Public Class OrderHeader
        Private m_sName As String
        Private m_iAge As Integer
    
        <XmlElement(ElementName:="OrderCompany")> _
        Public Property SHKCOO() As String
            Get
                Return m_sName
            End Get
            Set(ByVal sNewName As String)
                m_sName = sNewName
            End Set
        End Property
    
        <XmlElement(ElementName:="OrderNumber")> _
        Public Property SHDOCO() As Integer
            Get
                Return m_iAge
            End Get
            Set(ByVal iNewAge As Integer)
                m_iAge = iNewAge
            End Set
        End Property
    
    End Class
    Code:
    Public Function GetSeriaLized() As Object
    
            Dim oXS As XmlSerializer = New XmlSerializer(GetType(OrderHeader))
            Dim myOrderHeader As New OrderHeader()  'create instance of class
            Dim oStmW As StreamWriter
            Dim myDataRow As DataRow
    
            oStmW = New StreamWriter(Server.MapPath("orderheader.xml"))
    
            For Each myDataRow In mySqlDataTable.Rows
                myOrderHeader.SHKCOO = myDataRow.Item("SHKCOO").ToString
                myOrderHeader.SHDOCO = CInt(myDataRow.Item("SHDOCO"))
                oXS.Serialize(oStmW, myOrderHeader)
            Next
    
            oStmW.Close()
    
            Return oStmW
    
        End Function

    This codes writes the result to a .xml (located within the project). Is it possible to return this .xml file from the web method? If not, how could I write to a memory buffer and return that?

    I also tried this:

    Code:
    Public Function GetMemoryStream() As Object
    
            Dim myDataRow As DataRow
            Dim byteArray As Byte()
            Dim charArray As Char()
            Dim uniEncoding As New UnicodeEncoding()
            Dim myMemoryStream As New MemoryStream
            Dim firstString As Byte()
            Dim secondString As Byte()
    
            For Each myDataRow In mySqlDataTable.Rows
                 firstString = uniEncoding.GetBytes(myDataRow.Item("SHKCOO").ToString)
                secondString = uniEncoding.GetBytes(CInt(myDataRow.Item("SHDOCO")))
                myMemoryStream.Write(firstString, 0, firstString.Length)
                myMemoryStream.Write(secondString, 0, secondString.Length)
            Next
    
            Return myMemoryStream
    
        End Function
    Thanks again.
    Last edited by snufse; Aug 12th, 2011 at 01:01 PM.

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    arg... close... so close... you seem to have each of the concepts.. the list, the xml, the byte array... now it's time to put them all together.

    I'll put together a little more concrete example later tonight... show how it should all go together.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Smile Re: Webservice - return multiple records from table

    That is very kind of you .... thank you

  13. #13
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Webservice - return multiple records from table

    Hello,

    There are also some serialization links in my signature that might help you.

    Gary

  14. #14

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Question Re: Webservice - return multiple records from table

    I still have an issue with serialization and cannot get it to work:

    Code:
    <WebMethod()> _
        Public Function GetCustomerRecords_Serialized(ByVal myDateFrom As DateTime) As System.IO.MemoryStream
    
            OpenConnection()
            GetRecords(myDateFrom)
            CloseConnection()
            myFileStream = GetSeriaLized()
            Dim myMemorystream As New System.IO.MemoryStream
    
            myMemorystream = myFileStream
            Return myMemorystream
    
        End Function

    Code:
    Public Function GetSeriaLized() As Object
    
            Dim myXMLSerializer As XmlSerializer = New XmlSerializer(GetType(OrderHeader))
            Dim myOrderHeader As New OrderHeader()  'create instance of class
            Dim myDataRow As DataRow
    
            Dim myFileStream As FileStream = New FileStream("OrderHeader.xml", FileMode.Create)
    
            For Each myDataRow In mySqlDataTable.Rows
                myOrderHeader.SHKCOO = myDataRow.Item("SHKCOO").ToString
                myOrderHeader.SHDOCO = CInt(myDataRow.Item("SHDOCO"))
                myXMLSerializer.Serialize(myFileStream, myOrderHeader)
            Next
    
            Return myFileStream
    
        End Function
    When I query the OrderHeader.xml file the content is correct. But the file is not being displayed. Thank you.

  15. #15
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Webservice - return multiple records from table

    Hello,

    Have you stepped through the above code in the debugger, and look at the various steps?

    Had which point does it stop doing the expected thing?

    Gary

  16. #16
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    You're still trying to do it in two steps... need to combine it into a single step... don't use the file stream... use the memorystream:
    Code:
    Public Function GetSeriaLized() As MemoryStream 'Return the stream, instead of a generic object
    
            Dim myXMLSerializer As XmlSerializer = New XmlSerializer(GetType(OrderHeader))
            Dim myOrderHeader As OrderHeader
            Dim myOrders as new List(of OrderHeader)
    
            For Each myDataRow As DataRow In mySqlDataTable.Rows
                myOrderHeader  = New OrderHEader
                myOrderHeader.SHKCOO = myDataRow.Item("SHKCOO").ToString
                myOrderHeader.SHDOCO = CInt(myDataRow.Item("SHDOCO"))
                myOrders.Add(myOrderHeader) ' Add to the list
            Next
    
            Dim myStream As New System.IO.MemoryStream
    
            myXMLSerializer.Serialize(myStream, myOrders) ' -- serialize the WHOLE list, not a single item
    
            Return myStream
    
        End Function
    
    ...
    
    <WebMethod()> _
        Public Function GetCustomerRecords_Serialized(ByVal myDateFrom As DateTime) As Byte() 'Return an array of bytes
    
            OpenConnection()
            GetRecords(myDateFrom)
            CloseConnection()
    
            Dim myMemorystream As System.IO.MemoryStream = GetSeriaLized() 'Returns the memorystream
    
            Return myMemorystream.ToArray() ' Return it as an array of bytes
    
        End Function
    I've made a few changes in there... look through it... I tried to document what was going on where...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: Webservice - return multiple records from table

    Almost there, getting error:

    Code:
    System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[GetCustomerOrderHeaders.OrderHeader]' to type 'GetCustomerOrderHeaders.OrderHeader'.
       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterOrderHeader.Write3_OrderHeader(Object o)
    Line in error is:

    Code:
    myXMLSerializer.Serialize(myStream, myOrders)
    In the meantime I managed to use FileStream and Streamreader to populate an ArrayList, this solution not as good as yours.
    Last edited by snufse; Aug 15th, 2011 at 11:23 AM.

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    my bad... I missed one more change....

    change this:
    Code:
    Dim myXMLSerializer As XmlSerializer = New XmlSerializer(GetType(OrderHeader))
    to this:

    Code:
    Dim myXMLSerializer As XmlSerializer = New XmlSerializer(GetType(List(of OrderHeader)))
    That should do it...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: Webservice - return multiple records from table

    This is the outpout I get

    <?xml version="1.0" encoding="utf-8" ?>
    <base64Binary xmlns="http://GetCustomerRecords.org/">PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8QXJyYXlPZk9yZGVySGVhZGVyIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMj AwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiPg0KICA8T3 JkZXJIZWFkZXI+DQogICAgPE9yZGVyQ29tcGFueT4wMDAwMDwvT3JkZXJDb21wYW55Pg0KICAgIDxPcmRlck51bWJlcj4xMDA8L0 9yZGVyTnVtYmVyPg0KICA8L09yZGVySGVhZGVyPg0KICA8T3JkZXJIZWFkZXI+DQogICAgPE9yZGVyQ29tcGFueT4wMDAwMDwvT3 JkZXJDb21wYW55Pg0KICAgIDxPcmRlck51bWJlcj4xMDE8L09yZGVyTnVtYmVyPg0KICA8L09yZGVySGVhZGVyPg0KICA8T3JkZX JIZWFkZXI+DQogICAgPE9yZGVyQ29tcGFueT4wMDAwMDwvT3JkZXJDb21wYW55Pg0KICAgIDxPcmRlck51bWJlcj4xMDE8L09yZG VyTnVtYmVyPg0KICA8L09yZGVySGVhZGVyPg0KICA8T3JkZXJIZWFkZXI+DQogICAgPE9yZGVyQ29tcGFueT4wMDAwMDwvT3JkZX JDb21wYW55Pg0KICAgIDxPcmRlck51bWJlcj4xMDM8L09yZGVyTnVtYmVyPg0KICA8L09yZGVySGVhZGVyPg0KICA8T3JkZXJIZW FkZXI+DQogICAgPE9yZGVyQ29tcGFueT4wMDAwMDwvT3JkZXJDb21wYW55Pg0KICAgIDxPcmRlck51bWJlcj4xMDQ8L09yZGVyTn VtYmVyPg0KICA8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VtYmVyPg0KICA8L09yZ


    I am using:

    Code:
    <WebMethod()> _
        Public Function GetCustomerRecords_Serialized(ByVal myDateFrom As DateTime) As Byte() 'Return an array of bytes
    
            OpenConnection()
            GetRecords(myDateFrom)
            CloseConnection()
    
            Dim myMemorystream As System.IO.MemoryStream = GetSeriaLized() 'Returns the memorystream
    
            Return myMemorystream.ToArray() ' Return it as an array of bytes
    
        End Function
    The value of myOrders is correct:

    (1) = {GetCustomerOrderHeaders.OrderHeader}
    m_iAge = 100
    m_sName = "00000"
    SHDOCO = 100
    SHKCOO = "00000"
    Last edited by snufse; Aug 15th, 2011 at 12:19 PM.

  20. #20
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Webservice - return multiple records from table

    riiight.... ok... now how are you calling it? On the calling side, you have to reverse the process. take the returned byte array (on the client side now) ... use it to feed into a memory stream, feed that into the xml deserialization process and you should get a List(of OrderHeader) on the other end.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  21. #21

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: Webservice - return multiple records from table

    OK, you are way ahead of me. What you say makes sense. Since I now have 3 web method options I think I should be OK and I have learned alot.

    I also created another method that uses a entry in c:\temp with arraylist.

    Bottom line, I thank you very much for ALL you help and patience.


    Code:
    '<WebMethod()> _
        'Public Function GetCustomerRecords_Serialized(ByVal myDateFrom As DateTime) As ArrayList
    
        '    OpenConnection()
        '    GetRecords(myDateFrom)
        '    CloseConnection()
        '   Dim myArrayList As New ArrayList() = GetSeriaLized()
        '    Return myarraylist
    
        'End Function

    Code:
    'Public Function GetSeriaLized() As Object
    
        '    Dim myXMLSerializer As XmlSerializer = New XmlSerializer(GetType(OrderHeader))
        '    Dim myOrderHeader As New OrderHeader()  'create instance of class
        '    Dim myDataRow As DataRow
    
        '    Dim myFileStream As FileStream = New FileStream("C:\Temp\OrderHeader.xml", FileMode.Create, FileAccess.ReadWrite)
    
        '    For Each myDataRow In mySqlDataTable.Rows
        '        myOrderHeader.SHKCOO = myDataRow.Item("SHKCOO").ToString
        '        myOrderHeader.SHDOCO = CInt(myDataRow.Item("SHDOCO"))
        '        myXMLSerializer.Serialize(myFileStream, myOrderHeader)
        '    Next
    
        '    Dim myArrayList As New ArrayList()
        '    Dim myStreamReader As New StreamReader(myFileStream)
        '    myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin)
        '    While myStreamReader.Peek() > -1
        '        myArrayList.Add(myStreamReader.ReadLine())
        '    End While
    
        '    myStreamReader.Close()
        '    myFileStream.Close()
    
        '    Return myArrayList
    
        'End Function
    Result like this:

    Code:
    <?xml version="1.0" encoding="utf-8" ?> 
    - <ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://GetCustomerRecords.org/">
      <anyType xsi:type="xsd:string"><?xml version="1.0"?></anyType> 
      <anyType xsi:type="xsd:string"><OrderHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></anyType> 
      <anyType xsi:type="xsd:string"><OrderCompany>00000</OrderCompany></anyType> 
      <anyType xsi:type="xsd:string"><OrderNumber>100</OrderNumber></anyType> 
      <anyType xsi:type="xsd:string"></OrderHeader><?xml version="1.0"?></anyType> 
      <anyType xsi:type="xsd:string"><OrderHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></anyType> 
      <anyType xsi:type="xsd:string"><OrderCompany>00000</OrderCompany></anyType> 
      <anyType xsi:type="xsd:string"><OrderNumber>101</OrderNumber></anyType>
    Last edited by snufse; Aug 15th, 2011 at 12:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width