Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

c# - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...