通过WCF服务返回数据

时间:2014-06-26 17:41:56

标签: c# wcf windows-phone-8 geolocation

我希望通过WCF返回latitudelongitude个变量,以显示用户在地图上的位置。我可以返回latitude,但不能对longitude做同样的事情,因为方法只返回一个值。我想过返回数组,但不知道该怎么做。这是WP代码:

    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);      
    }

1 个答案:

答案 0 :(得分:1)

您必须定义一个类来保存这两个属性,并将其用作返回值:

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();
}