美好的一天每個人的列表...WCF異常:無法添加到已知類型
我得到了意想不到的WCF錯誤說「已知類型」,它的名稱相似,但在不同的名稱空間(見錯誤如下)。
...請記住,我仍在試驗這一切。
也...
我已經明白常規的網絡服務,迫使你壓扁的對象層次的性質,但一切我讀過說你沒有這樣做與WCF ......這是爲什麼我正在嘗試這個。
所以我的問題是...
- 問:是否可以告訴WCF來不要忽視 名稱間距?
- 問:我是否缺少標籤?不要WCF 標籤(下面)採取名稱間距爲 帳戶?
- 問:我是否需要將我的物體 層次化?
基本錯誤是...
類型 'wcfFISH.StateManagement.Contractor.New' 自其他類型 不能被添加到已知類型 的名單「wcfFISH.StateManagement.CostDivision 。' 具有相同的數據合同名稱 'wcfFISH.StateManagement.Contractor:新的' 已存在。
錯誤看起來像...
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
contract: http://tempuri.org/:IFishData ----> System.InvalidOperationException: Type 'wcfFISH.StateManagement.Contractor.New' cannot be added to list of known types since another type 'wcfFISH.StateManagement.CostDivision.New' with the same data contract name 'wcfFISH.StateManagement.Contractor:New' is already present.
at System.Runtime.Serialization.DataContract.CheckAndAdd(Type type, Dictionary`2 typesChecked, Dictionary`2& nameToDataContractTable)
at System.Runtime.Serialization.DataContract.ImportKnownTypeAttributes(Type type, Dictionary`2 typesChecked, Dictionary`2& knownDataContracts)
at System.Runtime.Serialization.DataContract.ImportKnownTypeAttributes(Type type)
at System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper.get_KnownDataContracts()
at System.Runtime.Serialization.ClassDataContract.get_KnownDataContracts()
at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
at System.Runtime.Serialization.DataContractSet.Add(XmlQualifiedName name, DataContract dataContract)
at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
at System.Runtime.Serialization.DataContractSet.Add(XmlQualifiedName name, DataContract dataContract)
at System.Runtime.Serialization.DataContractSet.Add(Type type)
at System.Runtime.Serialization.XsdDataContractExporter.Export(Type type)
at System.ServiceModel.Description.MessageContractExporter.ExportType(Type type, String partName, String operationName, XmlSchemaType& xsdType)
at System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32 messageIndex, Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32 messageIndex, Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext)
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
--- End of inner ExceptionDetail stack trace ---
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
at System.ServiceModel.Description.WsdlExporter.CallExportContract(WsdlContractConversionContext contractContext)
at System.ServiceModel.Description.WsdlExporter.ExportContract(ContractDescription contract)
at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName)
at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
at SyncInvokeGet(Object , Object[] , Object[])
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
服務代碼看起來像...
namespace wcfFISH.StateManagement
{
[DataContract(Namespace = "wcfFISH.StateManagement")]
[KnownType(typeof(wcfFISH.StateManagement.C1FE.Approved))]
[KnownType(typeof(wcfFISH.StateManagement.C1FE.Denied))]
[KnownType(typeof(wcfFISH.StateManagement.C1FE.New))]
[KnownType(typeof(wcfFISH.StateManagement.C1FE.Pending))]
[KnownType(typeof(wcfFISH.StateManagement.Contractor.Authenticated))]
[KnownType(typeof(wcfFISH.StateManagement.Contractor.New))]
[KnownType(typeof(wcfFISH.StateManagement.CostDivision.Authenticated))]
[KnownType(typeof(wcfFISH.StateManagement.CostDivision.New))]
[KnownType(typeof(wcfFISH.StateManagement.ReportingPeriod.Closed))]
[KnownType(typeof(wcfFISH.StateManagement.ReportingPeriod.Open))]
public abstract class ObjectState
{
#region CONSTRUCTORS
protected ObjectState()
{ }
#endregion
#region PROPERTIES & FIELDS
#endregion
#region EVENTS
#endregion
#region METHODS
#endregion
}
}
邊注...
另一個原因,我困惑的是原來的聲明下面列出永遠不會造成問題......它工作正常!這隻發生在我添加CostDivision時!
[KnownType(typeof(wcfFISH.StateManagement.C1FE.New))]
[KnownType(typeof(wcfFISH.StateManagement.Contractor.New))]
在情況下,我沒有說清楚...
我的理解是WCF應瞭解以下類之間的差異:
[KnownType(typeof(wcfFISH.StateManagement.Contractor.Authenticated))]
[KnownType(typeof(wcfFISH.StateManagement.Contractor.New))]
[KnownType(typeof(wcfFISH.StateManagement.CostDivision.Authenticated))]
[KnownType(typeof(wcfFISH.StateManagement.CostDivision.New))]
如果不明白...
我想我唯一的選擇似乎是把hiera弄平rchy一切爲:
wcfFISH.StateManagement.Authenticated
wcfFISH.StateManagement.New
...這是我唯一的選擇嗎? (希望不是!)
是的,這基本上是錯誤信息說的...... – 2010-04-19 14:16:31
DOH! ...你是對的! Muchas Thankas! – 2010-04-19 15:04:04
沒問題,很高興我能幫到你。讓我們聽聽它的精神力量! 8) – Task 2010-04-19 15:19:38