我有一个 WCF 服务项目,它构建得很好,可以生成可访问的 WSDL,并且 svcutil.exe 不会生成任何错误。
我有一个访问该 Web 服务的“服务管理器”项目,并且我已成功向其中添加了服务引用 ABCService。
第三个项目包含我需要来回传递的所有 POCO 对象 - 用 [DataContract] 和 [DataMember] 属性自由装饰。
当我尝试构建解决方案时,我看到 ABCService 的 Reference.cs 有这样的方法(为了简洁起见,我用 (...) 替换了完整的命名空间):
public (...).Thing SaveThing((...).Thing objThing) {
return base.Channel.SaveThing(objThing);
}
public (...).myCollectionOfThing0mj5ZrAW GetThings() {
return base.Channel.GetThings();
}
第一个方法返回单个 Thing,工作正常 - 但每个 MyCollection 方法都会出现错误:
错误 16 参数 1:无法从 '(...).MyCollection' 转换为 '(...).myCollectionOfThing0mj5ZrAW'
我的集合类按照您的预期进行装饰:
[CollectionDataContract]
public class MyCollection<T> : List<T> where T : BaseType
{
// ...
}
我不知道为什么它会生成时髦的“myCollectionOfThing0mj5ZrAW”名称,也不知道为什么从一个到另一个的翻译失败
EDIT 1:我尝试过使用
[CollectionDataContract(Name= "myCollection{0}", ItemName = "{0}")]
装饰我的集合类,我得到了相同的错误,但名称更新了:
错误 12 参数 1:无法从 '(...).myCollection' 转换
到“(...).myCollectionThing”
EDIT 2:
Despite having checked the "Reuse types in referenced assemblies", selected the radio button for "specified referenced assemblies", and checking the box next to my POCO assembly:
...仍然使用唯一的类名生成服务引用: