简体   繁体   English

WCF 服务引用作为数组与列表<T>

[英]WCF Service Reference as array vs. List<T>

We have an asp website with service references to a WCF project.我们有一个 asp 网站,其中包含对 WCF 项目的服务引用。 We have set the configuration of the service collection type to System.Collection.Generic.List, yet the reference.cs is showing arrays.我们已经将服务集合类型的配置设置为 System.Collection.Generic.List,但 reference.cs 显示的是数组。 We can see我们可以看到

<CollectionMappings>
      <CollectionMapping TypeName="System.Collections.Generic.List`1" Category="List" />
</CollectionMappings>

in the reference.svcmap.在reference.svcmap 中。

We would prefer to work with List if possible.如果可能,我们更愿意使用 List。 What are we missing?我们缺少什么? Why is it insisting to build a reference full of arrays when it has been told to convert them to Lists?当它被告知将它们转换为列表时,为什么它坚持构建一个充满数组的引用?

Visual Studio 2019, asp.net 4.8 Visual Studio 2019,asp.net 4.8

Set in the Add Service Reference tool:在添加服务引用工具中设置:

在此处输入图片说明

在此处输入图片说明

Finally, apply this setting to generate a proxy class.最后,应用此设置以生成代理类。

For those that run across this: It's actually an “undocumented feature” of visual studio... thank you Microsoft.对于那些遇到这个问题的人:它实际上是 Visual Studio 的一个“未记录的功能”......谢谢微软。 When using the XML Serializer instead of the DataContract serializer, the service connection tool in visual studio doesn't create the classes as requested.使用 XML 序列化程序而不是 DataContract 序列化程序时,visual studio 中的服务连接工具不会按要求创建类。 You can manually alter the reference.cs, or move to webAPI using .net core.您可以手动更改 reference.cs,或使用 .net core 移动到 webAPI。

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

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