2010-08-17 29 views
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類型‘System.Collections.Generic.List`1 [T1]’不能導出爲一個模式類型,因爲它是一個開放的泛型類型,你只能當導出一個泛型類型所有通用參數類型都是實際類型。「如果我主持這份合同。通用的ServiceContract

我已經讀過,很好的避免了在ServiceContract中的泛型。但是有可能使用T?

+0

端點定義不正確。您已指定IPolicyProvider,因此您只能獲取在IPolicyProvider中定義的操作,而不是在ISecurities中定義的操作。 – 2010-08-17 15:40:27

+0

你真棒!刪除IPolicyProvider,它工作。但ISecurities必須實施IPolicyProvider。我如何獲得這兩項業務? – Bhaskar 2010-08-17 15:50:44

+0

您必須添加暴露ISecurities但具體指定具體類型的endpoit。 – 2010-08-17 15:53:16

回答

3

在這種情況下,您的問題不是T在ServiceContract中,而是用作DataContract的T1。如果在服務合同實施期間用特定類型替換T,則可以在服務合同中使用T.對於數據合約(操作參數和返回類型),您根本不能使用T.你總是必須指定具體的類型。可以使用ServiceKnownTypeAttribute重寫您的服務合同,以便用FI_CusipMaster替換T1,並且ServiceKnownType指定從FI_CusipMaster派生的所有可能的類。

編輯:另一種方法是不使用ServiceKnownType並使用必須在FI_CusipMaster類型上定義的KnownTypeAttribute。

此致敬禮拉迪斯拉夫

+0

誓言中暴露此終結點!有用!!。非常感謝!! – Bhaskar 2010-08-17 14:20:04

+0

我能夠託管合同,但在創建代理時不顯示泛型方法(添加服務引用) – Bhaskar 2010-08-17 15:17:09

+0

您能提供合同實施和主機+配置嗎?當我不知道你是如何執行它的時候,很難說。 – 2010-08-17 15:23:23

1

正如錯誤所述,不可以使用T.服務契約需要能夠寫出處理確定類型的序列化信息。它不能處理導出函數中的開放泛型

1

在您的示例中,T 的泛型類型。除非與定義的類型參數一起使用,否則不能在ServiceContract中使用泛型類型,如class Foo : List<int> { }

相關問題