Re: WCF Contract Design Best Practices Question
- From: ronscottlangham@xxxxxxxxx
- Date: Sat, 18 Aug 2007 11:34:01 -0700
On Aug 17, 1:05 pm, "FlyFishGuy" <FlyFish...@xxxxxxxxxxxxx> wrote:
I'm fairly new to WCF. I have a project, which I already have a lot of time
already invested it, which involves much data processing and cross
application communication. WCF seemed like a great way to go, moving
forward.
I have been diligently designing thread-safe classes to meet future needs.
WCF doesn't seem to like classes without Set methods, so I find myself
butchering work I have already done to be able to pass my objects back and
forth over the wire.
Being new to all of this, I don't want to take the wrong path, with regard
to my design principles. In a situation where I want to utilize my existing
code and plan well for future development, I'm in need of a sound approach.
It just seems as my classes grow in complexity, I'm faced with the options
of stripping them down to work with WCF or creating redundant copies of the
classes, which are difficult to maintain.
Should I just forget about readonly properties and private variables and
make everything public variables? Should I create a duplicate watered down
version of every class I have to accomplish the same thing? Does it make
sense to inherit WCF amicable classes from my existing classes and extend my
readonly properties with write access? Should I be attempting to add the
<DataMember> attribute to my private variables and ressurect public access
on the client?
I just don't want to go down the wrong path and regret it later. I can see
already that I'm going to have to make compromises, I just don't want to end
up in a box.
Any thoughts, suggestions, or references to documentation would be greatly
appreciated.
In my experience, I generally create separate classes with public
properties that are used just for the web service. I tend to keep
these separate and hopefully static without being affected by my
underlying classes. I then have conversion routines that will convert
one from the other. But, it sounds like that you have a lot of
classes, and this hasn't always been my case. But, I prefer having
the separate web service objects so I can fine tune them for their
purpose without having to push this requirement down to my other
business objects.
I tend to make them separate in hopefully also keeping the web service
mostly static and not changing much since this may require that the
client also be kept up to date. Not a big problem for internal
products, but could be a bigger issue if distributed to external
customers. You may want to update logic and classes on the server
without it affecting the clients.
Also, some .NET objects cannot be serialized directly across the wire,
such as Collections. So, the web objects may be an array of object,
e.g. foo[] GetFoos(), while the internal business objects may be
collection or other non-web service compliant object.
If you do have a lot of classes, possibly you could use a generic
conversion method between web service objects and business objects
using reflection without having to write a custom convert function for
each one. Could be a little slower if lots of objects, so something
to consider.
I have also used general objects for passing values that I expect to
change. For example, may create a Property object that has a name and
value, and then add array of the Property objects to another class.
This allow me to pass general property values without having to create
a specific new property for each item. Allows some extensibility
without having to change the web service contract.
Ron
.
- Follow-Ups:
- Re: WCF Contract Design Best Practices Question
- From: FlyFishGuy
- Re: WCF Contract Design Best Practices Question
- References:
- WCF Contract Design Best Practices Question
- From: FlyFishGuy
- WCF Contract Design Best Practices Question
- Prev by Date: Re: Web Service doesn't return needed values
- Next by Date: Re: Starting to learn WCF
- Previous by thread: WCF Contract Design Best Practices Question
- Next by thread: Re: WCF Contract Design Best Practices Question
- Index(es):
Relevant Pages
|