locked
Converting BING REST Service XML response in Typed Dataset. RRS feed

  • Question

  • Hi All,

    I'm trying to convert XML response from BING REST service into Typed dataset and reading XML Response into that typed dataset, I managed to generate schema information in XSD format but when reading XML it gives following error:

    "The same table 'BoundingBox' cannot be the child table in two nested relations."

    http://dev.virtualearth.net/REST/V1/Routes/Driving?wp.0=EA81GN&wp.1=EA70TH&output=xml&avoid=tolls&key=BINGKEY

    Is there any way I can convert XML Response in Typed dataset OR any other better solution, I don't want to use untyped dataset in code.

    Here is Code :

     

    protected

    void btnRoute_Click(object sender, EventArgs e)

    {

     

    string reqURL = "http://dev.virtualearth.net/REST/V1/Routes/Driving?wp.0=EA31GN&wp.1=EA10TH&output=xml&avoid=tolls&key=BING";

    BingMapsSample2005.

     

    DrivingRoute ds = GetXmlResponseTyped(reqURL);

    DisplayRouteInfoTypedDataSet(ds);

    }

     

    //DrivingRoute is a typed DataSet generated by REST Service response.
     

     

    private DrivingRoute GetXmlResponseTyped(string requestUrl)

    {

    HttpWebRequest request = WebRequest.Create(requestUrl)

    as HttpWebRequest;

    request.Method =

    "Get";

     

     

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

    {

    XmlDocument xmlDoc =

    new XmlDocument();

    xmlDoc.Load(response.GetResponseStream());

    XmlNodeReader xmlReader =

    new XmlNodeReader(xmlDoc);

     

    DrivingRoute ds = new DrivingRoute(); // Error is here: "The same table 'BoundingBox' cannot be the child table in two nested relations."
     

    ds.ReadXml(xmlReader);

     

    //ds.ReadXmlSchema(xmlReader);

     

    //ds.WriteXmlSchema(@"c:\DrivingRoute.xsd"); //here Typed dataset was generated before it was used to read XML.

     

    //ds.WriteXml(@"c:\DrivingRoute.xml");

     

    return ds;

    }

    }

     

     

    private void DisplayRouteInfoTypedDataSet(BingMapsSample2005.DrivingRoute ds)

    {

    StringBuilder directions =

    new StringBuilder();

    directions.Append(

     

    "Distance(km): " + ds.Route[0].TravelDistance.ToString() + " Time(min): " + (Convert.ToInt32(ds.Route[0].TravelDuration) / 60).ToString() + "<br>");

     

    foreach (DrivingRoute.RouteLegRow dr in ds.RouteLeg.Rows)

    {

    directions.Append(

     

    "Itinerary Leg: " + Convert.ToInt32(dr.RouteLeg_Id) + 1 + "<br>");

     

    foreach (DrivingRoute.ItineraryItemRow drItinaryItem in ds.ItineraryItem.Select("RouteLeg_Id=" + dr.RouteLeg_Id))

    {

     

    DrivingRoute.InstructionRow[] drInstruction = (DrivingRoute.InstructionRow[])ds.Instruction.Select("ItineraryItem_Id=" + drItinaryItem.ItineraryItem_Id);

    directions.Append(

     

    " " + drInstruction[0].Instruction_Text.ToString() + " Distance: " + drItinaryItem.TravelDistance + " km, " + drItinaryItem.TravelDuration.ToString() + " sec" + "<br>");

    }

    }

    labelResults.Text = directions.ToString();

    }

    • Edited by Vikasvirgo Thursday, September 29, 2011 11:13 AM
    • Moved by Ricky_Brundritt Saturday, March 10, 2012 12:05 PM (From:Bing Maps: Map Control and Web services Development)
    Thursday, September 29, 2011 11:08 AM

Answers

  • Check the generated class. It sounds like you might have a recursive reference to the BoundingBox property/class.
    http://rbrundritt.wordpress.com
    Friday, November 18, 2011 11:32 AM