Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:08:47+00:00 2026-06-06T07:08:47+00:00

Our WCF service has just one method: [ServiceContract(Name = Service, Namespace = http://myservice/)] [ServiceKnownType(GetServiceKnownTypes,

  • 0

Our WCF service has just one method:

[ServiceContract(Name = "Service", Namespace = "http://myservice/")]
[ServiceKnownType("GetServiceKnownTypes", typeof(Service))]
public interface IService {
     Response Execute(Request request);
}

public class Service : IService {
     public static IEnumerable<Type> GetServiceKnownTypes(ICustomAttributeProvider provider) {
        return KnownTypesResolver.GetKnownTypes();
     }

     public Response Execute(Request request) { 
         return new MyResponse { Result = MyEnumHere.FirstValue }; 
     }
}

Both the Request and Response class includes a ParameterCollection member.

[Serializable]
[CollectionDataContract(Name = "ParameterCollection", Namespace = "http://myservice/")]
[KnownType("GetKnownTypes")]
public class ParameterCollection : Dictionary<string, object> {
        private static IEnumerable<Type> GetKnownTypes()
        {
            return KnownTypesResolver.GetKnownTypes();
        }
}

Subclasses of Request and Response store their values into the ParameterCollection value bag.

I am using the KnownTypesResolver class to provide type information across all Service objects.

public static class KnownTypesResolver {
     public static IEnumerable<Type> GetKnownTypes()
     {
         var asm = typeof(IService).Assembly;
         return asm
             .GetAllDerivedTypesOf<Response>() // an extension method
             .Concat(new Type[] {
                 typeof(MyEnumHere),
                 typeof(MyEnumHere?),
                 typeof(MyClassHere),
                 typeof(MyClassListHere),
             });
     }
}

If I’m not mistaken, everything should have proper type information for proxy class generation tools to produce well-defined classes client-side.
However, whenever one of the Response subclasses (i.e. MyResponse) contains an enum value such as MyEnumHere, WCF starts complaining that the deserializer has no knowledge of the MyEnumHere value. It should have. I provided a KnownTypeAttribute for this very reason.

The client-side proxy class does have a MyEnumHere enum in the Reference.cs file; the problem is that the ParameterCollection class has no KnownTypeAttributes generated for it.

I resorted to hand-editing and including the following lines in the generated Reference.cs file:

//>
[KnownTypeAttribute(typeof(MyEnumHere))]
[KnownTypeAttribute(typeof(MyEnumHere?))]
[KnownTypeAttribute(typeof(MyClassHere))]
[KnownTypeAttribute(typeof(MyClassListHere))]
//<
public class ParameterCollection : Dictionary<string, object> { /* ... */ }

Hand-editing generated files is horrible. But this makes the clients work. What am I doing wrong? How can I define my Service objects so that the VS-proxy classes that are generated are correct from the get-go?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:08:49+00:00Added an answer on June 6, 2026 at 7:08 am

    WCF does not work well with Dictionary because it is not interoperable. You may use Array, List or custom collection to make sure that your data is properly serialized.

    Code below uses List<ParamCollectionElement> instead of Dictionary. I also removed some redundant attributes.

    [DataContract]
    public class Request
    {
        [DataMember]
        public ParameterCollection ParameterCollection { get; set; }
    }
    
    [DataContract]
    public class Response
    {
        [DataMember]
        public ParameterCollection ParameterCollection { get; set; }
    }
    
    [DataContract]
    public class MyResponse : Response
    {
        [DataMember]
        public MyEnumHere Result { get; set; }
    }
    
    public class ParamCollectionElement
    {
        public string Key { get; set; }
        public object Value { get; set; } 
    }
    
    
    [CollectionDataContract(Name = "ParameterCollection")]
    public class ParameterCollection : List<ParamCollectionElement> 
    {
    
    }
    
    public static class KnownTypesResolver
    {
        public static IEnumerable<Type> GetKnownTypes()
        {
            return
                new Type[] {
                    typeof(MyEnumHere),
                    typeof(MyEnumHere?),
                    typeof(Request),
                    typeof(Response),
                    typeof(MyResponse)
                };
        }
    }
    
    [DataContract]
    public enum MyEnumHere
    {
        [EnumMember]
        FirstValue,
        [EnumMember]
        SecondValue
    }
    
    [ServiceKnownType("GetServiceKnownTypes", typeof(Service))]
    [ServiceContract(Name = "Service")]
    public interface IService
    {
        [OperationContract]
        Response Execute(Request request);
    }
    
    public class Service : IService
    {
        public static IEnumerable<Type> GetServiceKnownTypes(ICustomAttributeProvider provider)
        {
            return KnownTypesResolver.GetKnownTypes();
        }
    
        public Response Execute(Request request)
        {
            var result = new MyResponse
            {
                Result = MyEnumHere.FirstValue,
                ParameterCollection = new ParameterCollection()
            };
    
            result.ParameterCollection.Add(new ParamCollectionElement {Key = "one", Value = MyEnumHere.FirstValue});
            result.ParameterCollection.Add(new ParamCollectionElement { Key = "two", Value = new Response() });
            return result;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are currently doing a review of our WCF service design and one thing
I am creating a net.tcp based WCF service to control one of our backend
Moving forward with re-designing a web service architecture using WCF, our team has been
I have a WCF service that provides access to some data. Our client has
While getting our WCF Data Service ready for production we encountered an issue with
We will write WCF service for our windows mobile client. Although we have the
I have a WCF service setup to control a USB fingerprint reader from our
We have a Data Access service in our SOA WCF system. This service is
We are looking at switching from using WCF for our service layer in applications
I've succeeded in getting WCF Transport security going for our Logon web service using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.