我一直在尝试在我的localhost和调试中使用web服务,但它给了我这个错误:
System.InvalidOperationException:类型'ParticipantDataService.Participant + OutsideAccountDetails + FundCollection'的DataContract无法添加到DataContractSet,因为类型'ParticipantDataService.Participant + FundCollection'在命名空间'http:// schemas中具有相同的数据协定名称'ArrayOfFundDetails' .datacontract.org / 2004/07 / ParticipantDataService'已经存在且合同不相等。
之前有没有人有这个错误?
感谢。
下面的简化代码(注意:不是我的代码。我正在修改以前开发人员的代码,不再在这里了。也是一个noobie w / web services。在下面这个代码块中,因为这个问题似乎与资金有关现在,我已经使所有'基金'参考文献比其他参考文献更明显了。谢谢。)
Namespace COMParticipantNameSpace
<DataContract(Namespace:="XYZ", Name:="COMParticipant"),
KnownType(GetType(COMParticipant))> _
Public Class COMParticipant
Inherits COMResponse
Private _FullName As FullName
(Other initialized variables...)
Protected Friend Sub New...
#Region "Properties"
<DataMember(Name:="Name", Order:=0)>...
<Other DataMembers...>
#End Region
#Region "Structures"
Public Structure FullName...
(Other Public Structures)
#End Region
#Region "Classes"
<DataContract(Name:="ParticipantPortfolio")>....
Public Class GroupCollection...
End Class
<DataContract(Name:="Group")>...
<DataMember(Name:="Funds", Order:=6)> _
Public Property Funds() As COMFundCollection
Get
Return _Funds
End Get
Set(ByVal value As COMFundCollection)
_Funds = value
End Set
End Property
End Class
Public Class COMAccountCollection
Inherits System.Collections.ObjectModel.Collection(Of COMAccountDetails)
End Class
<DataContract(Name:="COMAccountDetails")> _
Public Class COMAccountDetails
(Other initialized variables...)
Private _Funds As COMFundCollection
<DataMember Order 0,1,2,3,etc...)>...
<DataMember(Name:="Funds", Order:=7)> _
Public Property Funds() As COMFundCollection
Get
Return _Funds
End Get
Set(ByVal value As COMFundCollection)
_Funds = value
End Set
End Property
End Class
Public Class COMFundCollection
Inherits System.Collections.ObjectModel.Collection(Of COMFundDetails)
End Class
Public Class OutsideAccountCollection
End Class
<DataContract(Name:="OutsideAccountDetails")> _
Public Class OutsideAccountDetails
(Other initialized variables...)
Private _Funds As FundCollection
<Order 1, 2, 3, etc...>
<DataMember(Name:="Funds", Order:=15)> _
Public Property Funds() As FundCollection
Get
Return _Funds
End Get
Set(ByVal value As FundCollection)
_Funds = value
End Set
End Property
Public Class FundCollection
Inherits System.Collections.ObjectModel.Collection(Of FundDetails)
End Class
<DataContract(Name:="FundDetails")>...
End Class
Public Class TransactionTypeCollection
Inherits System.Collections.ObjectModel.Collection(Of TransactionTypeDetail)
End Class
Public Class TransactionTypeDetail...
Public Class TransactionCollection...
<DataContract(Name:="Transaction")> _
Public Class Transaction
(Other initialized variables...)
Private _Funds As TransactionFundCollection
<DataMember Order 1,2,3,etc ...>
<DataMember(Name:="Funds", Order:=7)> _
Public Property Funds() As TransactionFundCollection
Get
Return _Funds
End Get
Set(ByVal value As TransactionFundCollection)
_Funds = value
End Set
End Property
End Class
Public Class TransactionFundCollection
Inherits System.Collections.ObjectModel.Collection(Of TransactionFundDetails)
End Class
#End Region
End Class
End Namespace}
答案 0 :(得分:0)
虽然不是您问题的解决方案,但我收到了同样的错误消息。所以,我认为其他人在这里发布它是有用的。就我而言,它与链继承有关。
我在名为DerivedTypes的基类上有一个静态方法(很像这里描述的:Generally accepted way to avoid KnownType attribute for every derived class),它调用扩展方法来确定它的继承人。
如果你有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()将不会调用其父类。由于A没有子类,因此不需要KnownType属性。
顺便说一句,我对扩展方法所做的修改是扩展方法使用类型中的程序集(所以Assembly.GetAssembly(baseType)
),我将静态方法内部用于测试目的。私人也应该没事。