通过WCF服务返回数据

本文关键字:数据 返回 服务 WCF 通过 | 更新日期: 2023-09-27 18:10:37

我想通过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);      
    }

通过WCF服务返回数据

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

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