1
[ServiceContract]
public interface ISecurities<T> : IPolicyProvider where T: EntityObject 
{
  [OperationContract(Name="GetAllSecurities")]
    IEnumerable<T> GetSecurities();

  [OperationContract]
  IEnumerable<T> GetSecurities<T1>(List<T1> lstIdentifiers) where T1 : FI_CusipMaster;

  [OperationContract]
  T GetSecurity<T1>(T1 lstIdentifiers) where T1 : FI_CusipMaster;
}

//Host
        ///CADIS Contract
        ServiceHost dmHost = new System.ServiceModel.ServiceHost(typeof(GlobalInvestors.FIPA.BLL.UDI.CADISSecurities));

        Uri baseAddress = dmHost.BaseAddresses[0];
        Uri policyAddress = new Uri(baseAddress.AbsoluteUri.Replace(baseAddress.AbsolutePath, ""));

        dmHost.AddServiceEndpoint(
            typeof(GlobalInvestors.FIPA.BLL.IPolicyProvider),
            new System.ServiceModel.WebHttpBinding(),
            policyAddress).Behaviors.Add(new System.ServiceModel.Description.WebHttpBehavior());

        dmHost.Open();

 //App.Config
  <service behaviorConfiguration="UDIBehaviour" name="GlobalInvestors.FIPA.BLL.UDI.CADISSecurities">
    <endpoint binding="basicHttpBinding" contract="GlobalInvestors.FIPA.BLL.UDI.ICADISSecurities" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:1667/CADIS" />
      </baseAddresses>
    </host>
  </service>
  <behavior name="UDIBehaviour">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>

[ServiceContract]
[ServiceKnownType(typeof(SecurityMasterAdapter))]
public interface ICADISSecurities :ISecurities<SecurityMasterAdapter>
{

}

「InvalidDataContractException Type 'System.Collections.Generic.List`1[T1]' cannot be export as a schema type because it is an open generic type. ジェネリック型をエクスポートできるのは、すべてのジェネリック パラメーターの型が実際の型である場合のみです。 ." 私がこの契約をホストする場合。

ServiceContract ではジェネリックを避けるのが良いと読みました。しかし、Tを使用することは可能ですか?

4

3 に答える 3

3

この場合の問題は ServiceContract の T ではなく、DataContract として使用される T1 です。サービス コントラクトの実装時に T を特定の型に置き換えると、サービス コントラクトで T を使用できます。データ コントラクト (操作パラメーターと戻り値の型) の場合、T はまったく使用できません。常に具象型を指定する必要があります。T1 が FI_CusipMaster に置き換えられ、ServiceKnownType が FI_CusipMaster から派生したすべての可能なクラスを指定するように、ServiceKnownTypeAttribute を使用してサービス コントラクトを書き換えることができます。

編集:もう 1 つの方法は、ServiceKnownType を使用せず、FI_CusipMaster タイプで定義する必要がある KnownTypeAttribute を使用することです。

よろしく、ラディスラフ

于 2010-08-17T13:55:05.950 に答える
1

エラーが示すように、T を使用することはできません。サービス コントラクトは、決定的な型を扱うシリアル化情報を書き出すことができる必要があります。エクスポートされた関数でオープンジェネリックを処理できません

于 2010-08-17T13:47:07.773 に答える
1

あなたの例では、 Tジェネリック型です。のように、定義済みの型パラメーターと共に使用しない限り、ServiceContract でジェネリック型を使用することはできませんclass Foo : List<int> { }

于 2010-08-17T13:49:03.057 に答える