Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't my operation contracts in my wcf client take interfaces as parameters?

I have a simple wcf Service Contract that works fine if I use the concrete implementations for the interfaces, but if I want to use the interfaces in the paramaters instead of the concrete classes, it gives me the error which I will display below.

Here is code:

[ServiceContract]
public interface IClientUserRegistration
{
    [OperationContract]
    void RegisterClientUser(ClientUser clientUser);

    [OperationContract]
    List<ClientUser> GetUsers();
}

If I replace ClientUser with IClientUser, the WCF Test Client says that RegisterClientUser operation is not supported because it uses the type System.Object. If I replace the return value of GetUsers with List, it says that this operation is not supported because it uses the type System.Object[]. Why does it give these errors?

The reason why I was trying to use IClientUser is that I could implement different user types that implement the IClientUser interface and pass them into RegisterClient, but if I am only able to pass ClientUser, then I have to create a bunch of RegisterClient overrides that take different types of Users.

like image 567
Xaisoft Avatar asked Sep 15 '10 18:09

Xaisoft


2 Answers

SOAP has no concept of interfaces. That would tend to make deserialization difficult.

like image 56
John Saunders Avatar answered Nov 15 '22 14:11

John Saunders


This is because the objects have to be serialized for passing between the client and the server. You are not allowed to pass an "object" type. All types must be concrete so that they can be properly serialized and deserialized. An Interface is nothing more than an "object" type with a sub-type of the Interface. The object as a whole cannot be deserialized and serialized this way, only the interface members can be. This would make for a really messy implementation on both sides.

like image 27
Nathan Wheeler Avatar answered Nov 15 '22 16:11

Nathan Wheeler