tags:

views:

137

answers:

1

Hi, I'm generating a WCF Proxy to my contract. The contract contain classes that are implementing an Interface. on the Generated proxy the interface is gone. so I can't use it.

Is there a way to mark the interface in some way to be generated on the proxy file ?

Here is a contact example:

public interface IMyGeneralInterface
{    
   int? ID { get; set; }
}

[DataContract]
public abstract class EntityBase : IMyGeneralInterface
{        
  [DataMember]
  public virtual int? ID { get; set; }
}

The Generated proxy will not contain any definition, of IMyGeneralInterface which will not enable me to use it one the client side.

What should I do ?

Thanks, Dani

+2  A: 

The messages being exchanged between the client and the server must be concrete classes that can be serialized and deserialized between sender and receiver. This makes it virtually impossible to send back and forth interfaces. The important thing is: you're exchanging messages between client and server - NOT objects with information and behaviors.

All the client sees when he imports the service description is a data contract of type "EntityBase" - he doesn't see anything else. The data is described in XML schema, and XML schema does not have a concept of interfaces.

Remember: WCF is interoperable - your client could be a PHP or Java client, and they might not support the notion of interfaces.

The only thing you could do if you control both ends of the service (both server and client) is to put your service and data contracts into their own assembly and then share that assembly between the client and the server. That way, you can "transport" more information about your service and your data contracts between your client and server, BUT you loose any chance of interoperability in the process.

See these blog posts for more info on sharing assemblies between WCF client and server:

Marc

marc_s
Hi Marc, We used this method, but it made us some problems, as all the collection we've passed through WCF became arrays (and thus we couldn't add anything to them).so the solution was to use a generated proxy (which solved that problem) and now I'm working on separating the Generated staff from the shared dll, and here we are with interfaces.I am thinking that we might be able to keep them in the shared dll (as we don't need interoperability, and try mix both generated proxy file and shared dll in the same solution.
Dani
Well, that's another thing: basically, all the XML schema supports in terms of "collection" is the Array - there's nothing else in XML Schema. But you can specify (when you create your proxy) that you want to forgo this limitation and use Collections or generic lists - again, loosing some interoperability, but making things easier for the pure .NET dev shop. Check out the various options on the "Add Service Reference" screen (or the command-line options for `svcutil.exe` )
marc_s