tags:

views:

370

answers:

3

Lets say I have some interfaces:

public interface IFoo {
  IBar DoesStuff();
}
public interface IBar {
  string Thingo { get; }
}

I'm consuming this code throughout my code base. The IFoo process needs to be moved onto a different system (a difference of x64 vs x32), this is our reason for using WFC. My WCF service implements this interface. When I create the "service reference" the proxy stubs are created but the interface is altered.

public interface IFoo {
   object DoesStuff();
}

I tried defining IBar/Bar as both a DataService and DataContract with no difference. Is there a way to generate the proxy code using my interface?

I'm thinking if mock objects can produce a object of my interface for testing, then shouldn't I be able to get the service to honor it as well? Or did do something silly and wrong?

A: 

Yes. You need to reference the project containing the interface before you add the service reference. Then the interface will be re-used. The same will be true for any custom classes used - if the project containing their definitions is referenced by the client project before the service reference is added, then WCF can re-use those definitions.

You will also need to go to the Advanced tab in the Add Service Reference dialog and tick "Reuse types in referenced assemblies" to get this to work.

David M
I did have the project referenced prior to generating the proxy. It was in use through out my code base already.
Mike
Edited my post with more details - can you try this now?
David M
thanks for the input!!That option was already selected. I tried the explicit option as well to tell it which specific assembly to reuse from but it still comes back as an object.
Mike
+3  A: 

IBar needs to be concrete and a DataContract. WCF isn't about distributed objects, but rather a way to transfer data and have services work on that data. You can't return an object in WCF that has behavior.

Scott Weinstein
I'm not from your first statement if I was clear there was a backing concrete Bar object that was defined as a DataContract that implmented IBar. I don't have behavior in the returned object. It only contains property getters. I know under the hood that getters are methods. What you describe is ultimately what I'm after; process somewhere else and return object with the data in it. The data is yes defined as an interface.
Mike
btw thank you for the input!!
Mike
Think of WCF as facilitating message exchange, rather than making objects or interfaces available across networks. The ]DataContract] stuff in WCF allows you to *map* between the properties and fields of a class to a message, and vice versa. You are not actually sending the class (or instance) across the wire, just the message that it maps to.
Cheeso
A: 

Try to think of web services as being cross-platform. What would a Java client do with your interface if you returned it?

John Saunders
Thanks for the input!I really am trying to just pass data around! ;) I would still think that a data centric interface should be allowed and marking it with the appropriate attributes could achieve that ends.
Mike
SOAP, WSDL, XSD, XML have no concept of an interface. If you write a DataContract, you are, in effect, creating a data-centric interface, in that the only thing that will get passed is the data.
John Saunders