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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:14:24+00:00 2026-06-01T22:14:24+00:00

I have a ServiceContract which returns dynamic type and looks like following: public dynamic

  • 0

I have a ServiceContract which returns dynamic type and looks like following:

public dynamic LoginViaOpenId(string openIdUrl)

The dynamic return type could be a DataContract that I have defined, or a string. But since I have not used my DataContract on the service, client does not know anything about it and cannot access it.

My DataContract is something like below:

[DataContract]
public enum OpenIdStatus
{
        [EnumMember]
        Authenticated,
        [EnumMember]
        Authenticating,
        [EnumMember]
        Cancelled,
        [EnumMember]
        Failed,
        [EnumMember]
        RedirectToLogon
 }

I know if I had hierarchical types I could have used KnownType to conquer this, but am out of idea for this scenario.
Any idea?

  • 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-01T22:14:26+00:00Added an answer on June 1, 2026 at 10:14 pm

    A dynamic DataContract is an oxymoron. A DataContract is a predetermined and mutually agreed-upon data structure, and dynamic is an object whose structure is not predetermined and thus cannot be agreed-upon, since it can be anything.

    It doesn’t appear you actually need to return a dynamic data type, but rather a varying data type. The difference is that a varying data type is one of a set of fixed data types, whereas a dynamic data type is one which does not have a predetermined structure. Since your return value is one of several knows shapes, there is no need to use the “shapeless” (or “freeform”) dynamic type, which isn’t supported by WCF.

    Instead, you could have the [OperationContract] method return a type with a [DataContract] that will act as a wrapper object that has a single data member of type object, and use [KnownType] on the wrapper object to specify the possible types that may be returned inside the wrapper. Since everything inherits from object, there is already a hierarchy in place.

    [DataContract]
    [KnownType(typeof(OpenIdStatus))]
    [KnownType(typeof(string))]
    public class ReturnValue
    {
        [DataMember]
        public object Value { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF-REST service with one method which returns a string: [ServiceContract] public
I have the following: [ServiceContract] [ServiceKnownType(typeof(ActionParameters))] [ServiceKnownType(typeof(SportProgram))] [ServiceKnownType(typeof(ActionResult<SportProgram>))] public interface ISportProgramBl { [OperationContract] IActionResult<ISportProgram>
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
I have a service with multiple contracts like so. [ServiceContract] public partial interface IBusinessFunctionDAO
I have an Service which I'd like to use properties from my client: [ServiceContract]
I have a WCF service which has one method returning a stream. [ServiceContract] public
I have created a Silverlight enabled WCF Service which looks like : I am
I would like to create a service which returns a simple string. So far
Let's say I have a WCF contract such as [ServiceContract] public interface IContract {
This question was asked at interview. Say I have a contract. [ServiceContract] public interface

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.