.NET Framework Developer Center >
.NET Development Forums
>
Windows Communication Foundation
>
Is there a way to allow client to use my lookup data without modifying them?
Is there a way to allow client to use my lookup data without modifying them?
- I am trying to figure out how to ensure that a client does not modify list data that I am providing and expecting to receive back as parameters.
For example, lets say that I have a Vehicle data contract. I want to allow a client to create a Vehicle. So I also have a CreateVehicle() Operation Contract. Now my CreateVehicle() takes several parameters to create:
CreateVehicle(vehicleColor, vehicleType)
I want to provide the client with a VehicleType DataContract so that they can only create vehicles of the types that I am providing and prevent them from modifying the types I am providing.
What is the best way to accomplish this?
Answers
- If type safety is a concern, you should design your DTO classes with great care using the basic OOD principles (inheritance, etc.). There is no generic solution for your problem. I can tell you from experience that persisting on type safety can complicate your design a lot (e.g. a lot of 'duplications' occur) and you have to sometimes choose between that and simplicity (this includes additional effort of validation).RegardsStipe Ivan
- Marked As Answer bySteven Cheng - MSFTMSFT, ModeratorMonday, November 16, 2009 3:39 AM
All Replies
- If I got you right, the vehicleType parameter should be an enumeration holding all the predefined members. Client will use your enumeration and won't be able to change it. This is how you define it:
[DataContract] VehicleType { [EnumMember] Car, [EnumMember] Bus, [EnumMember] Truck }Did this answer your question?Regards,Stipe Ivan Yes an enum would certainly work but we have many lookup types and some of them have many values. The vehicle was just a simple example. I want to provide these from our backend resources as they may often change. I'm not sure you can dynamically create enums without some workaround code.
- my opinion,either use hash function on the data contract or cache it on the server in order to
check if was changed - What about read only properties? That would obviously be the best solution but it seems like this is not supported without some workarounds. What do other people do in this scenario? Surely I cannot be the only person that is providing "Lookup" types to the client and expecting them back as arguments to operations. In the big picture, how important is this validation? What I mean is that even in my backend system a developer could possibly create an object with the wrong arguments and it still be a valid object. In the vehicle example, if a client is trying to create a "Truck" and my operation contract to do so takes a vehicle type or even a vehicle type id as an argument and for whatever reason they pass in the type of a Car or the id of a car, its still a valid vehicle.
- If type safety is a concern, you should design your DTO classes with great care using the basic OOD principles (inheritance, etc.). There is no generic solution for your problem. I can tell you from experience that persisting on type safety can complicate your design a lot (e.g. a lot of 'duplications' occur) and you have to sometimes choose between that and simplicity (this includes additional effort of validation).RegardsStipe Ivan
- Marked As Answer bySteven Cheng - MSFTMSFT, ModeratorMonday, November 16, 2009 3:39 AM


