0

ローカルホストで Web サービスを動作させてデバッグしようとしましたが、次のエラーが表示されます。

System.InvalidOperationException: 名前空間 'http://schemas.datacontract. org/2004/07/ParticipantDataService' は既に存在し、コントラクトは同等ではありません。

以前にこのエラーが発生した人はいますか?

ありがとう。

以下の要約コード (注: 私のコードではありません。私は以前の開発者のコ​​ードを変更していますが、彼はもうここにはいません。Web サービスの初心者でもあります。以下のこのコード ブロックでは、この問題は現在資金にあるように思われるため、すべての「資金」参照を他のものよりも見やすくしました. ありがとう.)

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}
4

1 に答える 1

0

問題の解決策ではありませんが、同じエラー メッセージが表示されました。ですから、他の人がここに投稿することは有益だと思います。私の場合、チェーン継承に関連していました。

DerivedTypes と呼ばれる基本クラスに静的メソッドがありました (ここで説明したように:すべての派生クラスの KnownType 属性を回避するための一般的に受け入れられている方法)。拡張メソッドを呼び出して継承者を決定します。

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 属性は必要ありません。

ところで、私が拡張メソッドに加えた変更は、拡張メソッドが型 (so Assembly.GetAssembly(baseType)) のアセンブリを使用し、テスト目的で静的メソッドを内部に作成したことです。プライベートでもいいです。

于 2014-10-14T14:23:30.063 に答える