简体   繁体   English

WCF服务的对象设计

[英]Object design for WCF service

I am writing a small WCF service to return an address based on GPS data. 我正在编写一个小的WCF服务,以基于GPS数据返回地址。 It's just a learning app for myself. 这只是我自己的学习应用程序。

At the moment, my WCF exposes an object type called GpsData, which has a Lat and Long. 此刻,我的WCF公开了一个名为GpsData的对象类型,该对象类型具有纬度和经度。 It's decorated as a [DataContract] . 它被装饰为[DataContract]

And then I have a method, getLocationByGpsData (GpsData); 然后我有一个方法getLocationByGpsData (GpsData);

On a project I recently worked on, they would have done it differently. 在我最近从事的一个项目中,他们会做不同的事情。 They had an object called LocationByGpsDataRequest , which then contained a GpsData object. 他们有一个名为LocationByGpsDataRequest的对象,该对象随后包含一个GpsData对象。 And it would return a ' LocationByGpsDataReply object, which had the GpsData object, as well as some extra address related data. 而且它会返回一个“ LocationByGpsDataReply对象,其中有GpsData对象,以及一些额外的地址相关的数据。

So: 所以:

LocationByGpsDataReply reply = getLocationByGpsData(new LocationByGpsDataRequest { Lat=...; long=...' };

Firstly, is their model better? 首先,他们的模型更好吗? Maybe it's more readable? 也许更具可读性?

Secondly, I don't really want to expose the GpsData object by it's self. 其次,我并不是真的想通过自身来公开GpsData对象。 It's ALWAYS contained in a parent class. 它总是包含在父类中。

var latitude = reply.GpsData.Latitude;

Is there a way to 'hide' GpsData is a stand alone object, so that when the client sees a list of ObjectTypes exposed by my WCF service, they only see the ones I intend them to use? 有没有办法“隐藏” GpsData是一个独立的对象,以便当客户端看到我的WCF服务公开的ObjectTypes列表时,他们只看到我打算使用的对象类型? Hope that makes sense... 希望有道理...

Yes i agree that the their approach is better. 是的,我同意他们的方法更好。

Also, the problem of hiding the attributes(lat, long) inside the GPSdata object can be achieved by using [Ignore Properties] tag. 另外,通过使用[Ignore Properties]标签可以隐藏GPSdata对象内部的属性(lat,long)。

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

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