views:

282

answers:

2

Hello,

I have a a datacontract which has important attributes on. For example, in the following code:

[DataMember]
[Description("My Description")]
public string Name { get; set; }

I want the Description attribute to be auto generated on the client proxy.

Is there any solution, or workarounds besides massive duplication?

Many thanks!

+1  A: 

You don't, not really. Remember that you're not passing instances of objects, but rather textual messages.

If it's really important then you can abandon the generated proxy classes and share implementation of the data objects and contracts instead, however this is a bunch more work and of course you're running the risk of the client and server becoming out of sync.

If you want to try that then put your contracts and operation interface into a separate assembly, with public modifiers, then try the following

Binding binding = new BasicHttpBinding(); // or which one you 
EndpointAddress endpoint = 
    new EndpointAddress("endpointUrl");
ChannelFactory<IServiceInterface> channelFactory = 
    new ChannelFactory<IServiceInterface>(binding, endpoint);

IServiceInterface client = channelFactory.CreateChannel();
MyDataType result = client.Operation(myOtherDataType);

((IClientChannel)client).Close();
blowdart
I forgot to mention, that my client is in Silverlight, which means that it's not possible to share assemblies (Or even the source code).
Tomerico
Well you could still share the project itself rather than the resultant DLL, and recompile it in each time.
blowdart
you can also link to the some source file from more then on project, this is what WCF RIA does with some of it's files.
Ian Ringrose
A: 

You would probably have to dig pretty deep into the creation of the service description (and the resulting WSDL file) in order to pass those attributes in such a form that the client could detect and recreate them. Next to impossible, really.

Plus: remember that WCF is designed to be interoperable - what should a Java or PHP client do with those attributes, really?

Service-oriented programming is quite a different beast from "regular" component- or object-based systems. All you do is basically pass around messages in text or binary format. That does limit certain things that you might be accustomed to when dealing with .NET based objects and components - it just works differently in SOA world.

Marc

marc_s