从Web服务返回XML数据

创建返回一组x,y坐标的Web服务的最佳方法是什么? 我不确定对象是最好的返回类型。 当我使用它的服务时,我想让它以xml的forms返回,例如:

  0 2   5 3   

如果有人有更好的结构返回请帮助我这一切都是新的。

由于您使用的是C#,因此非常简单。 我的代码假设您不需要反序列化,只需要一些客户端解析的XML:

 [WebService(Namespace = "http://webservices.mycompany.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class PointService : WebService { [WebMethod] public Points GetPoints() { return new Points(new List { new Point(0, 2), new Point(5, 3) }); } } [Serializable] public sealed class Point { private readonly int x; private readonly int y; public Point(int x, int y) { this.x = x; this.y = y; } private Point() { } [XmlAttribute] public int X { get { return this.x; } set { } } [XmlAttribute] public int Y { get { return this.y; } set { } } } [Serializable] [XmlRoot("Points")] public sealed class Points { private readonly List points; public Points(IEnumerable points) { this.points = new List(points); } private Points() { } [XmlElement("Point")] public List ThePoints { get { return this.points; } set { } } } 
      

或者,您可以改为使用JSON表示:

 [ { x:0, y:2 }, { x:5, y:10 } ]