I am writing a small WCF service to return an address based on GPS data. 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. It's decorated as a [DataContract]
.
And then I have a method, 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. And it would return a ' LocationByGpsDataReply
object, which had the GpsData object, as well as some extra address related data.
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. 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? 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.