Wcf 数据契约不是等价的

Wcf 数据契约不是等价的,wcf,soap,Wcf,Soap,我一直在尝试让Web服务在本地主机中运行并调试,但它给了我以下错误: System.InvalidOperationException:无法将类型“ParticipantDataService.Participant+OutsideAccountDetails+FundCollection”的DataContract添加到DataContractSet,因为命名空间中的类型“ParticipantDataService.Participant+FundCollection”具有相同的数据协定名称

我一直在尝试让Web服务在本地主机中运行并调试,但它给了我以下错误:

System.InvalidOperationException:无法将类型“ParticipantDataService.Participant+OutsideAccountDetails+FundCollection”的DataContract添加到DataContractSet,因为命名空间中的类型“ParticipantDataService.Participant+FundCollection”具有相同的数据协定名称“ArrayOfFundDetails”'http://schemas.datacontract.org/2004/07/ParticipantDataService"已经存在,合同不对等

以前有人犯过这个错误吗

谢谢

下面的代码摘要(注意:不是我的代码。我正在修改以前的开发人员的代码,他已经不在这里了。也是一个noobie w/web services。在下面的代码块中,由于这个问题现在似乎与资金有关,我已经使所有的“资金”引用比其他人更可见。谢谢。)

名称空间比较名称空间
_
公共类比较仪
继承COMResponse
私有\u全名作为全名
(其他初始化变量…)
受保护的朋友子新。。。
#区域“财产”
...
#末端区域
#区域“结构”
公共结构全名。。。
(其他公共结构)
#末端区域
#区域“类”
....
公共类组集合。。。
末级
...
_
公共财产基金()作为COMFundCollection
得到
回报基金
结束
设置(ByVal值作为COMFundCollection)
_资金=价值
端集
端属性
末级
公共类COMAccountCollection
继承System.Collections.ObjectModel.Collection(COMAccountDetails的)
末级
_
公共类COMAccountDetails
(其他初始化变量…)
作为COMFundCollection的私人基金
...
_
公共财产基金()作为COMFundCollection
得到
回报基金
结束
设置(ByVal值作为COMFundCollection)
_资金=价值
端集
端属性
末级
公共类基金集合
继承System.Collections.ObjectModel.Collection(COMFundDetails的)
末级
公共类OutsideAccountCollection
末级
_
公共类OutsideAccountDetails
(其他初始化变量…)
私募基金作为基金募集
_
公共财产基金()作为基金募集
得到
回报基金
结束
设置(ByVal值作为FundCollection)
_资金=价值
端集
端属性
公开募捐
继承System.Collections.ObjectModel.Collection(基金详细信息的集合)
末级
...
末级
公共类TransactionTypeCollection
继承System.Collections.ObjectModel.Collection(TransactionTypeDetail的)
末级
公共类TransactionTypeDetail。。。
公共类TransactionCollection。。。
_
公共类事务
(其他初始化变量…)
私募基金作为交易基金集合
_
公共财产基金()作为交易基金集合
得到
回报基金
结束
设置(作为TransactionFundCollection的ByVal值)
_资金=价值
端集
端属性
末级
公共类TransactionFundCollection
继承System.Collections.ObjectModel.Collection(TransactionFundDetails的)
末级
#末端区域
末级
结束命名空间}

虽然不是您问题的解决方案,但我收到了相同的错误消息。所以,我认为其他人在这里发布它是有用的。在我的例子中,它与链式继承有关

我在一个名为DerivedTypes的基类上有一个静态方法(很像这里描述的:),它调用一个扩展方法来确定它的继承者

如果你有A:B,B:C,那么C应该是这样的:

[DataContract]
[KnownType("DerivedTypes")]
public class C {
  internal static Type[] DerivedTypes() {
    typeof(C).GetDerivedTypes();
  }
}
调用B.DerivedTypes()将(错误地)获得太多类型,因为它将调用
typeof(C).GetDerivedTypes()
。这在我的案例中引发了同样的错误

除非B是:

[DataContract]
[KnownType("DerivedTypes")]
public class B : C {
  internal **new** static Type[] DerivedTypes() {
    typeof(B).GetDerivedTypes();
  }
}
自然没有“**”这个词。现在,如果遇到类型B,B.DerivedTypes()将不会调用其父级。由于没有子类,因此不需要KnownType属性


顺便说一句,我对扩展方法所做的修改是,扩展方法使用类型中的程序集(因此
assembly.GetAssembly(baseType)
),我将静态方法设置为内部用于测试。Private也可以。

你有两个不同的名为“Fund”的课程吗?你能发布你的代码吗?请参考上面的编辑。谢谢-对不起,什么?
[DataContract]
[KnownType("DerivedTypes")]
public class B : C {
  internal **new** static Type[] DerivedTypes() {
    typeof(B).GetDerivedTypes();
  }
}