0

I have such a contract:

[DataContract] [KnownType(typeof(Person))] public class Gadget { [DataMember] public int Id { get; set; } [DataMember] public string Name { get; set; } [DataMember] public IPerson Person { get; set; } } 

It represents a gadget that belongs to a person. I just came up with this simple example, it's not important whether it makes sense or not.

So, instead of returning the Person class, I return the IPerson interface. Now the client can no longer generate a strong typed object, but will generate this:

public object Person { get; set; } 

Now my question is: is it possible to let the client also generate the IPerson interface? It should have enough information, because it can only instantiate Person (only known type).

1 Answer 1

1

Interfaces will not be transfered by adding a service reference. These interfaces only exist in .NET, but your service is suppossed to be interoperable.

As far as your WSDL is concerned there is likely to be no way to tell Person and IPerson apart.

If you really want to use that interface you will need to move it across manually. This means editing the generated client code by hand.

Sign up to request clarification or add additional context in comments.

2 Comments

Damn, that sucks. So you cannot provide clean interfaces that also have interface members? I need to implement explicit interfaces on the client and cast everything manually. Well, I'll do that then (but it's hard for collections and dictionaries).
It is not really that you need to cast. You should be able to just replace the line of code that says public object with public IPerson. The problem is that it is difficult to convay an interface definition using a WDSL, but instead you can easily just allow the client to referance the DLL which contains IPerson.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.