我们一直在使用Microsoft Sync Framework和WCF开发中心/辐射型同步模型,由于我们同时开发客户端和服务器,因此我们希望将WCF服务协定接口放入共享程序集中,以便我们可以只定义它一次,并在客户端和服务器之间共享它。这在很大程度上是可行的,但是Sync Framework的GetSchema方法传递了一个表名的集合对象,该对象被序列化并在客户机上作为string[]读取。但是,由于客户端代理已被编写为使用服务器接口,因此它期望接收一个Collection对象,而我得到了一个类型不匹配。
我只需将约定更改为仅显式传递string[],并在调用同步提供程序方法时手动强制转换它,但这会导致“找到不明确的匹配”错误。
如何在客户端和服务器上使用相同的接口并正确处理集合-> string[]序列化?
发布于 2011-11-10 01:45:26
我通过在传递给代理的Collection<string>
上使用ToArray()
LINQ扩展调用解决了这个问题:
public override SyncSchema GetSchema(System.Collections.ObjectModel.Collection<string> tableNames, SyncSession syncSession)
{
return this.ServiceProxy.GetSchema(tableNames.ToArray(), syncSession);
}
服务器上的协定指定了IEnumerable<string>
而不是Collection<string>
。
public SyncSchema GetSchema(IEnumerable<string> tableNames, SyncSession syncSession)
{
// Convert IEnumerable<string> to Collection<string>
Collection<string> tables = new Collection<string>(tableNames.ToList());
return this.syncProvider.GetSchema(tables, syncSession);
}
https://stackoverflow.com/questions/7726966
复制相似问题