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

  • Home
  • SEARCH
  • 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 7796959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:31:56+00:00 2026-06-01T23:31:56+00:00

I want a loosely typed parameter in my web method. I have a scenario

  • 0

I want a loosely typed parameter in my web method.

I have a scenario where the client can send any of 25 DataContract objects into the WCF operation e.g.

proxy1.myFunction(PersonObject)
proxy1.myFunction(ComputerObject)

My restriction is there should be only one Operation Contract exposed to the client.

How can I design a web method which can take any of the 25 DataContract classes as a parameter? I tried with object as type of parameter and gave KnownType attribute to the DataContract classes but I had no luck during the serialization process.

  • 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-01T23:31:58+00:00Added an answer on June 1, 2026 at 11:31 pm

    I have just done this, I found you need to add the KnownTypesAttribute to the interface.

    [ServiceContract]
    [ServiceKnownType(typeof(MyContract1)]
    [ServiceKnownType(typeof(MyContract2)]
    [ServiceKnownType(typeof(MyContract3)]
    public interface IMyService
    {
        [OperationContract]
        object TakeMessage();
    
        [OperationContract]
        void AddMessage(object contract);
    
    }
    

    in you implementation, you will need to check the type to ensure it is one of your DataContracts.

    EDIT

    If you have a lot of contracts, you can use reflection to add them to the KnownTypes.

    internal static class KnownTypeHelper
    {
        public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider = null)
        {
            var types = Assembly.GetExecutingAssembly().GetTypes().Where(a => a.Namespace == "Company.Path.To.DataContractsNamespace").ToArray();
    
            return types;
        }
    }
    

    Then you can declare your interface as,

    [ServiceContract]
    [ServiceKnownType("GetKnownTypes", typeof(KnownTypeHelper))]
    public interface IMyService
    {
        [OperationContract]
        object TakeMessage( );
    
        [OperationContract]
        void AddMessage(object contract);
    }
    

    This is a much cleaner way of doing it.

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

Sidebar

Related Questions

I want to (loosely) have a stored procedure like select * from table where
want to have a Hyperlink-Button in a gridView in which I can display a
An Observer Design Pattern is the solution to loosely coupling objects so they can
I want to create a spring-ws web service that eventually marshals a POJO into
Want to be able to provide a search interface for a collection of objects
Want to send the text from my current vb application to the Active Window
I have a class called EditMapUtilities. Here are some class properties that I want
I have an applicaion, that can best be described 'loosly' as a scripting application,
Say I have the title of a Wikipedia article, e.g. Philadelphia, and I want
What is a good method for loosely-coupled inter-controller communication in MVC/MVP? For example, in

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.