Peter
Peter

Reputation: 761

Returning data via WCF service

I want to return latitude and longitude variables via WCF to show user's location on the map. I can return the latitude, but can't do the same thing with the longitude, because method returns only one value. I thought about returning array, but don't know how to do that. Here is WP code:

    void proxy_getUsrLatCompleted(object sender, ServiceReference1.getUsrLatCompletedEventArgs e)
    {
        Grid MyGrid = new Grid();
        MyGrid.RowDefinitions.Add(new RowDefinition());
        MyGrid.RowDefinitions.Add(new RowDefinition());
        MyGrid.Background = new SolidColorBrush(Colors.Transparent);

        Rectangle MyRectangle = new Rectangle();
        MyRectangle.Fill = new SolidColorBrush(Colors.Black);
        MyRectangle.Height = 20;
        MyRectangle.Width = 20;
        MyRectangle.SetValue(Grid.RowProperty, 0);
        MyRectangle.SetValue(Grid.ColumnProperty, 0);

        MyGrid.Children.Add(MyRectangle);

        Polygon MyPolygon = new Polygon();
        MyPolygon.Points.Add(new Point(2, 0));
        MyPolygon.Points.Add(new Point(22, 0));
        MyPolygon.Points.Add(new Point(2, 40));
        MyPolygon.Stroke = new SolidColorBrush(Colors.Black);
        MyPolygon.Fill = new SolidColorBrush(Colors.Black);
        MyPolygon.SetValue(Grid.RowProperty, 1);
        MyPolygon.SetValue(Grid.ColumnProperty, 0);

        MyGrid.Children.Add(MyPolygon);

        MapOverlay MyOverlay = new MapOverlay();
        MyOverlay.Content = MyGrid;
        MyOverlay.PositionOrigin = new Point(0, 0.5);
        MapLayer MyLayer = new MapLayer();
        MyLayer.Add(MyOverlay);
        myMap.Layers.Add(MyLayer);

        float gLat = float.Parse(e.Result);
        myMap.Center = new GeoCoordinate(gLat, gLong);
        MyOverlay.GeoCoordinate = new GeoCoordinate(gLat, gLong);      
    }

Upvotes: 0

Views: 141

Answers (1)

Rayyan
Rayyan

Reputation: 61

You must define a class to hold both properties, and use it as the return value:

class Point
{
    public string Lat {get;set;}
    public string Lon {get;set}
}
public Point getUsrLocation(string uName)
{
    DataClasses1DataContext data = new DataClasses1DataContext();
    return (from s in data.Users where s.usrName == uName select new Point(){Lat=s.usrLat,Lon=s.usrLong}).Single();
}

Upvotes: 1

Related Questions