Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET and SOAP - multiple records in a datagridview

Posted on 2010-09-15
3
Medium Priority
?
847 Views
Last Modified: 2012-06-22
I am working with an external SOAP webservice that contains real-time information about ships around the world. I have successfully written code that passes username, password and IMO number and returns information about a single ship. I am now trying to pass username, password and bounding latitude/longitude values to return information on all of the ships in the area.

My question is how to handle multiple records (multiple ships). Getting information about 1 ship was easy, I would declare a new vessel and get the returned name, call sign, destination, status, etc. Now I need to get all of that information for multiple ships. I would like to bind this to a datatable and write it to a text file. I think I just need a little direction about how to read the data (XMLreader? something else to store response into a table?) and I can take it from there.

My code for one vessel and the SOAP response for multiple records is attached.

Thanks in advance!

My code for getting information on one ship:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'initiate service
        Dim svc As New ServiceReference1.VtrServiceClient

        'set up an instance of vessel class to contain ship information
        Dim jdvessel As New ServiceReference1.vessel
        Dim jdTable As New DataTable("vessel")

        Try
            jdvessel = svc.getVesselByIMO("myusername", "password", 123456)

            jdTable.Columns.Add("Call Sign")
            jdTable.Columns.Add("Name")
            jdTable.Columns.Add("Destination")
            jdTable.Columns.Add("Status")

            Dim row1 As DataRow

            row1 = jdTable.NewRow
            row1.Item("Call Sign") = jdvessel.sCallsign.ToString
            row1.Item("Name") = jdvessel.sName.ToString
            row1.Item("Destination") = jdvessel.sDestination.ToString
            row1.Item("Status") = jdvessel.sStatus.ToString

            jdTable.Rows.Add(row1)

            DataGridView1.DataSource = jdTable

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub


SOAP response for more than one vessel:

<S:Body>
        <ns2:getVesselsInAreaResponse xmlns:ns2="http://webservice.ejb.vesseltracker.com/">
            <return>
                <nMMSI>211177390</nMMSI>
                <dAgeMinutes>-2.4091</dAgeMinutes>
                <dLat>53.856178283691406</dLat>
                <dLon>8.72246265411377</dLon>
                <dSoG>0.0</dSoG>
                <nWidth>10</nWidth>
                <nLength>100</nLength>
                <dDraught>0.0</dDraught>
                <sName>ALASCO</sName>
                <sCallsign>DC5553</sCallsign>
                <sDestination/>
                <sStatus>moored</sStatus>
                <sVesselType>Cargo ship</sVesselType>
            </return>
            <return>
                <nMMSI>211223460</nMMSI>
                <nIMO>8521426</nIMO>
                <dAgeMinutes>-2.4924333333333335</dAgeMinutes>
                <dLat>53.858768463134766</dLat>
                <dLon>8.717516899108887</dLon>
                <dHeading>314.0</dHeading>
                <dSoG>0.0</dSoG>
                <nWidth>12</nWidth>
                <nLength>51</nLength>
                <dDraught>3.4</dDraught>
                <sName>ATAIR</sName>
                <sCallsign>DBBI</sCallsign>
                <sDestination>Cuxhaven</sDestination>
                <dtETA>2010-09-08T10:00:00+02:00</dtETA>
                <sStatus>moored</sStatus>
                <sVesselType>Unknown type of ship</sVesselType>
            </return>
</S:Body>

Open in new window

0
Comment
Question by:dobbinjp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 33689114
You can read the xml-string into a dataset directly

example below:

Some remarks: you need to remove the ns from the xml
       string myXml = "<S:Body>" +
                    //"<ns2:getVesselsInAreaResponse xmlns:ns2=\"http://webservice.ejb.vesseltracker.com/\">" + 
                    "<return>" + 
                        "<nMMSI>211177390</nMMSI>" + 
                        "<dAgeMinutes>-2.4091</dAgeMinutes>" + 
                        "<dLat>53.856178283691406</dLat>" + 
                        "<dLon>8.72246265411377</dLon>" + 
                        "<dSoG>0.0</dSoG>" + 
                        "<nWidth>10</nWidth>" + 
                        "<nLength>100</nLength>" + 
                        "<dDraught>0.0</dDraught>" + 
                        "<sName>ALASCO</sName>" + 
                        "<sCallsign>DC5553</sCallsign>" + 
                        "<sDestination/>" + 
                        "<sStatus>moored</sStatus>" + 
                        "<sVesselType>Cargo ship</sVesselType>" + 
                    "</return>" + 
                    "<return>" + 
                        "<nMMSI>211223460</nMMSI>" + 
                        "<nIMO>8521426</nIMO>" + 
                        "<dAgeMinutes>-2.4924333333333335</dAgeMinutes>" + 
                        "<dLat>53.858768463134766</dLat>" + 
                        "<dLon>8.717516899108887</dLon>" + 
                        "<dHeading>314.0</dHeading>" + 
                        "<dSoG>0.0</dSoG>" + 
                        "<nWidth>12</nWidth>" + 
                        "<nLength>51</nLength>" + 
                        "<dDraught>3.4</dDraught>" + 
                        "<sName>ATAIR</sName>" + 
                        "<sCallsign>DBBI</sCallsign>" + 
                        "<sDestination>Cuxhaven</sDestination>" + 
                        "<dtETA>2010-09-08T10:00:00+02:00</dtETA>" + 
                        "<sStatus>moored</sStatus>" + 
                        "<sVesselType>Unknown type of ship</sVesselType>" + 
                    "</return>" + 
                "</S:Body>";
            //myXml = myXml.Substring(myXml.IndexOf("<return>"));
            myXml = myXml.Replace("S:Body", "Body");
            XmlReader xmlReader = new XmlTextReader(new MemoryStream(ASCIIEncoding.Default.GetBytes(myXml)));
            DataSet ds = new DataSet();

            ds.ReadXml(xmlReader);

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34881975
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For some reason Google Apps has decided to reserve 'www' for your new domain which results in an error when trying to map the web address 'www' to a certain site in your Google Sites. The error is 'this address is already being used' and after some …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

610 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