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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:52:25+00:00 2026-06-07T13:52:25+00:00

I’m pretty sure it hasn’t, but apologies if this question has already been asked.

  • 0

I’m pretty sure it hasn’t, but apologies if this question has already been asked. And additional apologies if this is just flat out a dumb question but I feel like I’m either completely missing something or have the right idea and just need some backup for my own sanity.

I’ve been implementing WCF Data Services 5.0 in our application and am having no issues with read operations returning entity objects.

Unfortunately there is that nasty limitation when it comes to service operations that they can only return primitive types (See MSDN). It’s very annoying given that it has no problems with the entity objects.

I know that one workaround is to create a “dummy” complex type since WCFDS will recognize that but I don’t want to just throw random POCOs into my data model that aren’t actually in the database.

So the solution that occurred to me was to create an extension method for my objects that can serialize them into JSON strings to be returned by the service. My question is; are there any compelling arguments why I shouldn’t do this or can anyone suggest any better alternatives?


Edit: Additional information to clarify my current issues

I created a very simple example of what I’m doing that originally raised this question. My service class follows first:

[JsonpSupportBehavior]
public partial class SchedulingService : DataService<ChronosDataContext>, ISchedulingService
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        #if DEBUG
        config.UseVerboseErrors = true;
        #endif

        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;

        config.SetServiceOperationAccessRule(
        "TestService",
        ServiceOperationRights.All);
    }

    [WebGet]
    public SchedulingResult TestService(
         string testParam1,
         string testParam2)
    {
         // NOTE: I never use the params, they're just there for this example.
         SchedulingResult result = SchedulingResult.Empty;

         result.Status = OperationStatus.Success;
         result.ResponseID = Guid.NewGuid();
         result.AffectedIDs = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7 });
         result.RecordsAffected = 10;

         return result;
    }
}

Attempting to access this service using my browser, I get the following request error:

The server encountered an error processing the request. The exception message is 
'Unable to load metadata for return type 
    'Chronos.Services.SchedulingResult' of method 
    'Chronos.Services.SchedulingResult TestService(System.String, System.String)'.'. 
See server logs for more details. 

The exception stack trace is:
at System.Data.Services.Providers.BaseServiceProvider.AddServiceOperation(MethodInfo method, String protocolMethod) 
at System.Data.Services.Providers.BaseServiceProvider.AddOperationsFromType(Type type) 
at System.Data.Services.Providers.BaseServiceProvider.LoadMetadata() 
at System.Data.Services.DataService`1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider& metadataProviderInstance, IDataServiceQueryProvider& queryProviderInstance, BaseServiceProvider& builtInProvider, Object& dataSourceInstance) 
at System.Data.Services.DataService`1.CreateProvider() 
at System.Data.Services.DataService`1.HandleRequest() 
at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) 
at SyncInvokeProcessRequestForMessage(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.ProcessMessage41(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Below are the classes that make up the SchedulingResult that I’m trying to return:

public class SchedulingResult : ServiceInvocationResponse
{
    public SchedulingResult()
        : base()
    {
        this.Payload = new object[] 
        {
            new List<int>(),
            new List<int>()
        };
    }

    public List<int> AffectedIDs 
    {
        get { return (List<int>)Payload[0]; }
        set { Payload[0] = value; }
    }

    public List<int> FailedIDs
    {
        get { return (List<int>)Payload[1]; }
        set { Payload[1] = value; }
    }

    public static SchedulingResult Empty
    {
        get { return new SchedulingResult(); }
    }
}

public class ServiceInvocationResponse : AbstractJsonObject<ServiceInvocationResponse>
{
    public ServiceInvocationResponse()
    {
        this.Status = OperationStatus.Unknown;
        this.Severity = ErrorSeverity.None;
    }

    public virtual int RecordsAffected { get; set; }

    public virtual Exception ErrorObject { get; set; }

    internal virtual object[] Payload { get; set; }
}


public abstract class AbstractJsonObject<TBaseType>
{
    public virtual object Deserialize(string source)
    {
        return JsonConvert.DeserializeObject(source);
    }

    public virtual T Deserialize<T>(string source)
    {
        return JsonConvert.DeserializeObject<T>(source);
    }

    public string Serialize()
    {
        return JsonConvert.SerializeObject(
            this, Formatting.Indented);
    }

    public override string ToString()
    {
        return this.Serialize();
    }

    public static TBaseType FromString(string json)
    {
        return JsonConvert.DeserializeObject<TBaseType>(json);
    }
}
  • 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-07T13:52:29+00:00Added an answer on June 7, 2026 at 1:52 pm

    It is possible to return one or many primitive, complex, or entity types from a service operation.

    • A primitive type is what you’d expect: string, int, bool, etc.
    • A complex type is a class that doesn’t have a unique key (a property named ID or the [DataServiceKey("<yourkeyhere>")] attribute)
    • An entity type is a class that does have a unique key

    For instance:

    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Linq;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    
    namespace Scratch.Web
    {
        [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
        public class ScratchService : DataService<ScratchContext>
        {
            public static void InitializeService(DataServiceConfiguration config)
            {
                config.SetEntitySetAccessRule("*", EntitySetRights.All);
                config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
                config.UseVerboseErrors = true;
            }
    
            [WebGet]
            public string GetPrimitive()
            {
                return "Success";
            }
    
            [WebGet]
            public IQueryable<string> GetPrimitives()
            {
                return new[] { "Success", "Hello World" }.AsQueryable();
            }
    
            [WebGet]
            public ComplexType GetComplexType()
            {
                return new ComplexType { Property1 = "Success", Property2 = "Hello World" };
            }
    
            [WebGet]
            public IQueryable<ComplexType> GetComplexTypes()
            {
                return new[] {
                               new ComplexType { Property1 = "Success", Property2 = "Hello World" },
                               new ComplexType { Property1 = "Success", Property2 = "Hello World" }
                           }.AsQueryable();
            }
    
            [WebGet]
            public EntityType GetEntityType()
            {
                return new EntityType { Property1 = "Success", Property2 = "Hello World" };
            }
    
            [WebGet]
            public IQueryable<EntityType> GetEntityTypes()
            {
                return new[] {
                               new EntityType { Property1 = "Success1", Property2 = "Hello World" },
                               new EntityType { Property1 = "Success2", Property2 = "Hello World" }
                           }.AsQueryable();
            }
        }
    
        public class ScratchContext { }
    
        public class ComplexType
        {
            public string Property1 { get; set; }
            public string Property2 { get; set; }
        }
    
        [DataServiceKey("Property1")]
        public class EntityType
        {
            public string Property1 { get; set; }
            public string Property2 { get; set; }
        }
    }
    

    Perhaps you’re running into some other problem?

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.