views:

308

answers:

1

Good Day Everyone...

I’m getting an unexpected WCF error complaining of “Known Types” which are similarly named, but in different name-spaces (see error below).

...please keep in mind I'm still experimenting with all this.

Also…

I already understand the nature of regular web-services FORCES you to flatten your object hierarchy, but everything I’ve read says you don’t have to do that with WCF…which is why I’m attempting this.

So my questions are…

  • Q: Is it possible to tell WCF to NOT TO IGNORE the name-spacing?
  • Q: Am I missing a tag? Don’t the WCF tags (below) take name-spacing into account?
  • Q: Do I HAVE to flatten my object hierarchy?

The basic error is…

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.

The error looks like…

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)

The service code looks like…

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

Side note…

Another reason I am confused is the original declarations listed below NEVER caused an issue...and it was working fine! This only happened when I ADDED CostDivision!

[KnownType(typeof(wcfFISH.StateManagement.C1FE.New))]
[KnownType(typeof(wcfFISH.StateManagement.Contractor.New))]

In case I’m not being clear…

My understanding is WCF should understand the difference between the following classes:

[KnownType(typeof(wcfFISH.StateManagement.Contractor.Authenticated))]
[KnownType(typeof(wcfFISH.StateManagement.Contractor.New))]
[KnownType(typeof(wcfFISH.StateManagement.CostDivision.Authenticated))]
[KnownType(typeof(wcfFISH.StateManagement.CostDivision.New))]

If it does NOT understand…

I guess my only option seems to be to flatten the hierarchy FOR EVERYTHING to:

wcfFISH.StateManagement.Authenticated
wcfFISH.StateManagement.New

…is this my only option? (hope not!)

+1  A: 

My psychic powers tell me that your declaration of wcfFISH.StateManagement.CostDivision.New was copy/pasted from wcfFISH.StateManagement.Contractor.New and while you changed the class name you didn't change the DataContract attribute on it to match.

Task
Yeah, this is basically what the error message says...
Stefan Steinegger
DOH! ...you are correct! Muchas Thankas!
No problem, glad I could help. Let's hear it for psychic powers! 8 )
Task