我試圖從REST WCF服務返回一個通用的ICollection。以下是可能的嗎?WCF WebGet和ICollection <>
[ServiceContract]
public class WebConfigurationManager {
[WebGet]
[OperationContract]
public ICollection<string> GetStrings() {
return new string[] { "A", "B", "C" };
}
}
當我嘗試從我的Web瀏覽器執行此操作時,出現錯誤。翻翻我的WCF跟蹤顯示我:
無法序列類型的參數「System.String []」(操作「GetStrings」,合同「WebConfigurationManager」),因爲它不是確切類型「System.Collections中.Generic.ICollection`1 [System.String]'在方法簽名中,不在已知類型集合中。爲了序列化參數,請將類型添加到使用ServiceKnownTypeAttribute的操作的已知類型集合中。