简体   繁体   English

通过WCF服务返回数据

[英]Returning data via WCF service

I want to return latitude and longitude variables via WCF to show user's location on the map. 我想通过WCF返回latitudelongitude变量,以在地图上显示用户的位置。 I can return the latitude , but can't do the same thing with the longitude , because method returns only one value. 我可以返回latitude ,但不能对longitude做同样的事情,因为method仅返回一个值。 I thought about returning array, but don't know how to do that. 我考虑过返回数组,但是不知道该怎么做。 Here is WP code: 这是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);      
    }

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM