【发布时间】:2011-05-09 06:38:57
【问题描述】:
我正在实现 WCF 服务,我希望以这样一种方式实现它,即客户端应该能够在服务器上执行命令,即使服务器上不存在该命令的实现。
代码应如下所示:
//Common interface - used by both client and server
public interface ICommand
{
//add whatever method/property is needed to achieve the goal
}
//Server side interface and implementation
[ServiceContract()]
public interface ICommandChannel
{
[OperationContract]
object ExecuteCommand(ICommand command, Guid clientId);
}
public class CommandExecutor : ICommandChannel
{
object ExecuteCommand(ICommand command, Guid clientId)
{
//this should be able to execute any command clients send
}
}
//Client side commands implementation
public class FileUploadCommand : ICommand
{
}
public class AuthorizeUSerCommand : ICommand
{
}
public class SubmitChangesCommand : ICommand
{
}
//etc
如果允许序列化方法,那么解决方案将非常简单,因为我们可以序列化ICommand 中定义的Execute 方法(和其他方法),通过通道发送,然后在服务器,并调用Execute 方法。但这是不可能的,因为不允许对方法进行序列化(据我所知)。
所以我的问题是,有没有办法解决这个问题?表达式树在这里有帮助吗?
编辑:
我不能让服务器知道实现。因为如果我这样做,那么每次在客户端添加新命令时,我都必须构建和部署服务。还是我错过了什么?
【问题讨论】:
标签: c# wcf web-services serialization service