Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF序列化列表对象为对象提供奇怪的名称_Wcf_Serialization - Fatal编程技术网

WCF序列化列表对象为对象提供奇怪的名称

WCF序列化列表对象为对象提供奇怪的名称,wcf,serialization,Wcf,Serialization,以下是WCF服务中的方法签名: APIMessageList<APISimpleContact> GetMembers(string apiKey, APIContactSearchFilter filter); APIMessageList GetMembers(字符串apiKey,APIContactSearchFilter); APIMessageList继承自IList。一旦我针对这个WCF服务构建了一个代理,类名就是APIMessageListOfAPISimpleC

以下是WCF服务中的方法签名:

APIMessageList<APISimpleContact> GetMembers(string apiKey, APIContactSearchFilter filter);
APIMessageList GetMembers(字符串apiKey,APIContactSearchFilter);

APIMessageList
继承自
IList
。一旦我针对这个WCF服务构建了一个代理,类名就是APIMessageListOfAPISimpleContactjHldnYZV

为什么我得不到:apmessagelistofapisimplecontact

它将随机文本添加到接口中每个APIMessageList对象的末尾(有几个),它们都以相同的几个字符结束-jHldnYZV。我在网上查找了可能的原因,但我找不到任何有这个问题的人的帖子

这是一个纯粹的装饰性问题,但此界面暴露于我们的外部客户,因此其外观很重要

有人知道我为什么会遇到这个问题吗

非常感谢

Joe

在使用泛型类型作为返回值时,我们遇到了类似的问题。如果我们没有指定具体类型,那么默认数据协定序列化程序或WCF序列化程序将无法推断返回实体的确切类型。因此,它为返回的类型生成一个随机类名

在我们的项目中,我们通过构建特定类型的数据契约克服了这个问题,该数据契约在WCF操作调用后返回相同的结果

我猜您使用的是泛型类型,序列化程序无法推断返回对象的类型

我建议您创建一个数据传输对象(DTO),并从WCF服务返回该对象。这将解决您的问题。

您的解决方案将在。基本上,由于可以有多个“SimpleContact”类(在不同的名称空间中),WCF将在合同名称的末尾添加一个消歧散列,这就是合同名称末尾的8个字符中的内容。但您可以通过使用CollectionDataContract及其Name属性来控制:

[CollectionDataContract(Name = "APIMessageListOfSimpleContract")]
public class APIMessageList : IList<SimpleContract> { ... }
[CollectionDataContract(Name=“apimessageListofSimpleContact”)]
公共类APIMessageList:IList{…}

您可以发布服务合同中的operation contract属性吗?@carlosfigueira answer中的链接介绍了为泛型设置序列化规则-您只需给它一个这样的模板<代码>[DataContract(Name=“Drawing_using_{1}\u brush_and_{0}\u shape”)]公共类绘图{//code未显示。}ps。为什么注释中的代码格式在这个网站上如此垃圾!!?