Click here to Skip to main content
16,009,150 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to write a WebService Method. And this method going to take a Latitude, a Longitude and distance parameters. If the distance is close to our node, it is going to show us the nearest nodes.
So I wrote something but I cannot make it clear and more detailed. Can you please help me?? And also I have got a XML file too. There are addresses and Branches in the file ...
Thanks !


C++
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
namespace Proje
{
    public class DistanceHelper
    {
        private double GetDistanceBetweenPoints(double lat1, double long1, double lat2, double long2)
        {
            double distance = 0;
            double dLat = (lat2 - lat1) / 180 * Math.PI;
            double dLong = (long2 - long1) / 180 * Math.PI;
            double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2)
                        + Math.Cos(lat2) * Math.Sin(dLong / 2) * Math.Sin(dLong / 2);
            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            double radiusE = 6378135;
            double radiusP = 6356750;

            double nr = Math.Pow(radiusE * radiusP * Math.Cos(lat1 / 180 * Math.PI), 2);
            double dr = Math.Pow(radiusE * Math.Cos(lat1 / 180 * Math.PI), 2)
                            + Math.Pow(radiusP * Math.Sin(lat1 / 180 * Math.PI), 2);
            double radius = Math.Sqrt(nr / dr);
            distance = radius * c;
            return distance;
        }

        public DataTable GetAppropriateBranches(int longtitude, int latitude, decimal distance)
        {
            DataTable dTable = new DataTable();
            XmlDocument xmlDoc = GetXmlDocument();
            DataTable returnValue = CreateDataTable();

            XmlNode mainNode = xmlDoc.ChildNodes[1];
            foreach (XmlNode childNode in mainNode.ChildNodes)
            {
                DataRow dRow = returnValue.NewRow();
                dRow["Adres"] = childNode.Attributes["Address"];
                dRow["Sube"] = childNode.Attributes["Branch"];
                returnValue.Rows.Add(dRow);
            }



            return dTable;
        }

        private DataTable CreateDataTable()
        {
            throw new NotImplementedException();
        }
        private XmlDocument GetXmlDocument()
        {
            throw new NotImplementedException();
        }
    }
}</pre>


--------------------------------------------------------------
<pre lang="cs">using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml;
namespace Proje
{
    /// &lt;summary&gt;
    /// Summary description for Service1
    /// &lt;/summary&gt;
    [WebService(Namespace = &quot;http://tempuri.org/&quot;)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebServicec
    {
        [WebMethod]
        public DataTable GetAppropriateBranches(int longtitude, int latitude, decimal distance)
        {
            return new DistanceHelper().GetAppropriateBranches(longtitude, latitude, distance);
        }
    }
}
Posted
Updated 19-Aug-10 5:40am
v2

1 solution

Is it the navigation of your xml that's causing you trouble? The code you've linked seems to be able to work out a distance and add new rows to your response table, so I'm guessing that querying your xml is your problem.


If that's the case, then System.Xml.XmlDocument.SelectNodes is the method you need - and you'll need to learn basic xpath.

Alternatively, you can search for "linq to xml" and there are plenty of good articles on how to query xml using linq.
 
Share this answer
 
v2

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