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 9247603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:46:16+00:00 2026-06-18T09:46:16+00:00

I had a WCF Service with an operation contract as void AddQuery(IQuery Query); My

  • 0

I had a WCF Service with an operation contract as

void AddQuery(IQuery Query);

My IQuery is like this

public interface IQuery
{
    Guid                Id { get; set; }        
    string              QueryNo { get; set; }
    string              Status { get; set; }
    IData               data { get; set; }
}

and the implementation of IQuery is in

[Serializable]
public class Query : IQuery
{
    Guid                Id { get; set; }        
    string              QueryNo { get; set; }
    string              Status { get; set; }
    IData               data { get; set; }
}

When i am trying to send my object from client as

  public void AddQuery(IQuery query)
  {
      try
      {
          // I am sure that the query object is not null and it is implemented
          objServiceClient.AddEnquiry(query);
      }
      catch (Exception ex)
      {
      }
  }

But i am getting an exception as

There was an error while trying to serialize parameter . The InnerException message was ‘Type ‘ViewModels.Query’ with data contract name ‘Query:http://schemas.datacontract.org/2004/07/ViewModels‘ is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.’. Please see InnerException for more details.

Could anyone suggest me what will be the resolution for this error?

  • 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-18T09:46:17+00:00Added an answer on June 18, 2026 at 9:46 am

    Consider serializing concrete classes. You cannot serialize interfaces . Refer to this answer: https://stackoverflow.com/a/4659289/860243

    Some useful links I found from bing:

    http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/

    The above article discusses your situation and examples of using [KnownType] for your derived classes

    Update:

    Based on this link, please check the below update:

    public interface IQuery 
    { 
        Guid Id { get; set; }
        string QueryNo{ get; set; } 
        string Status { get; set; } 
        IData data {get; set;}
    }
    

    Your Query class using Data contract serializer implementing your interface IQuery

    [DataContract]
    public class Query : IQuery
    {
        [DataMember]
        public Guid Id { get; set; };
        [DataMember]
        public string QueryNo { get; set; };
        [DataMember]
        public string Status { get; set; };
        [DataMember]
        public Data data { get; set; }; //Make sure you serialize Data class as well
    }
    

    And for your service contract:

    [ServiceContract]
    public interface IMyQueryService
    {
          [OperationContract]
          [ServiceKnownType(typeof(Query))]
          void AddQuery(IQuery query);
    }
    

    The [ServiceKnownType(typeof(Query))] will enable your operation contract to allow Query as input. Also please note you need to specify all your IQuery implementations that needs to be passed as parameters to your Operation contract with ServiceKnownType attribute .

    Also if you want more than one (or all) operation contract to take them as parameters, specify the ServiceKnownType attribute for ServiceContract instead of each operation contract separately.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I had a WCF service that I have coded up, like Clemens Vasters's
i created a wcf service that had a method: public List<Mail> GetMailItems() { //gets
I had a .asmx web service that check parameters of soap header like this:
Using the WCF web programming model one can specify an operation contract like so:
I am creating a WCF service. At first I had one WCF service library
All, My typical approach for a medium sized WCF service would be something like:
I have a WCF service which I would like to product XML and JSON
Using this tutorial: http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide I can get a Directory Listing to display when I
I had a wcf service, provided by one of our team which need to
I'm writing a WCF service in C#. Initially my implementation had a static constructor

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.