处理集合在具有共享 WCF 接口的客户端上
我们一直在使用 Microsoft Sync Framework 和 WCF 开发中心/辐射同步模型,并且由于我们同时开发客户端和服务器,因此我们希望将 WCF 服务契约接口放入共享程序集中,以便我们可以定义它一次并在客户端和服务器之间共享。在大多数情况下,这是可行的,但 Sync Framework 的 GetSchema 方法会传递一个表名称的 Collection 对象,该对象会被序列化并在客户端上作为 string[] 读取。但是,由于客户端代理已编写为使用服务器接口,因此它期望接收 Collection 对象,但我遇到了类型不匹配的问题。
我只是将合同更改为仅显式传递 string[],并在调用同步提供程序方法时手动转换它,但这会导致“发现不明确的匹配”错误。
如何在客户端和服务器上使用相同的接口并处理 Collection -> string[] 序列化正确吗?
We have been developing a hub/spoke synchronization model using Microsoft Sync Framework and WCF, and since we are developing both the client and the server, we would like to put the WCF service contract interface into a shared assembly so that we can define it just once and share it between the client and server. For the most part this works, but the GetSchema method of Sync Framework passes a Collection object of table names which gets serialized and read on the client as string[]. However, since the client proxy has been written to use the server interface it is expecting to receive a Collection object and I am getting a type mismatch.
I would just change the contract to explicitly pass only string[], and manually cast it when calling the sync provider methods, but this leads to an "ambiguous match found" error.
How can I use the same interface on both the client and server and handle the Collection -> string[] serialization correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过在传入代理的
Collection
上使用ToArray()
LINQ 扩展调用解决了这个问题:服务器上的合约指定了一个
IEnumerable
而不是Collection
。I solved this by using the
ToArray()
LINQ extension call on theCollection<string>
that is passed in to the proxy:The contract on the server specified an
IEnumerable<string>
instead of aCollection<string>
.