简体   繁体   English

将自定义对象从WCF服务传递到客户端

[英]Passing Custom objects from WCF service to Client

Just need some help with this. 只是需要一些帮助。

I have written a WCF service which passes through a list of custom objects (these objects are marked as serializable, so they pass through fine). 我编写了WCF服务,该服务通过自定义对象列表(这些对象被标记为可序列化,因此它们可以正常通过)。

What do I need to write in the client to be able to receive these objects? 我需要在客户端中写些什么才能接收这些对象? I'd like to be able to receive them without having a definition of the class locally. 我希望能够在没有本地定义类的情况下接收它们。 I tried getting them as an object but I get the error 我尝试将它们作为对象,但出现错误

Cannot implicitly convert type 'System.Collections.Generic.List<TestService.Member>' to 'System.Collections.Generic.List<object>' 无法将类型'System.Collections.Generic.List <TestService.Member>'隐式转换为'System.Collections.Generic.List <object>'

Hope this is enough information, any pointers would be useful. 希望这是足够的信息,任何指针都将是有用的。

I think you need to do a couple of things: 我认为您需要做几件事:

1) Create a custom class for this collection class that inherits from System.Collections.Generic.List 1)为此类创建一个自定义类,该类继承自System.Collections.Generic.List

2) Decorate this new class with CollectionDataContract 2)用CollectionDataContract装饰这个新类

3) In the client, edit reference.svcmap and add an entry for this new item to the CollectionMappings section. 3)在客户端中,编辑reference.svcmap并将此新项目的条目添加到CollectionMappings部分。 To find the svcmap, show all files in the project and expand the WCF service reference. 要找到svcmap,请显示项目中的所有文件,然后展开WCF服务参考。

For the class: 对于班级:

[CollectionDataContract]
public class MemberCollection: List<Member>

For the svcmap: 对于svcmap:

  <CollectionMapping TypeName="MyNameSpace.MemberCollection" Category="List" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM