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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:15:22+00:00 2026-05-26T22:15:22+00:00

I’ve followed this video series on WCF and have the demo working. It involves

  • 0

I’ve followed this video series on WCF and have the demo working. It involves building a WCF service that manages student evaluation forms, and implements CRUD operations to operate on a list of those evaluations. I’ve modified my code a little according to this guide so it will return JSON results to a browser or Fiddler request. My goal is to figure out how to use the service by building my own requests in Fiddler, and then use that format to consume the service from an app on a mobile device.

I’m having trouble using the SubmitEval method (save an evaluation) from Fiddler. The call works, but all the fields of Eval are null (or default) except Id, which is set in the service itself.

Here is my Eval declaration (using properties instead of fields as per this question):

[DataContract]
public class Eval //Models an evaluation
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Submitter { get; set; }

    [DataMember]
    public string Comment { get; set; }

    [DataMember]
    public DateTime TimeSubmitted { get; set; }
}

And here is the relevant part of IEvalService:

[ServiceContract]
public interface IEvalService
{
 ...
   [OperationContract]
    [WebInvoke(RequestFormat=WebMessageFormat.Json,
       ResponseFormat=WebMessageFormat.Json, UriTemplate = "eval")]
    void SubmitEval(Eval eval);
}

And EvalService:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
class EvalService : IEvalService
{
...
  public void SubmitEval(Eval eval)
    {
        eval.Id = Guid.NewGuid().ToString();
        Console.WriteLine("Received eval");
        evals.Add(eval);
    }
}

In Fiddler’s Request Builder, I set the Method to POST and the address to http://localhost:49444/EvalServiceSite/Eval.svc/eval. I added the header Content-Type: application/json; charset=utf-8 to the default headers. The request body is:

{"eval":{"Comment":"testComment222","Id":"doesntMatter", 
  "Submitter":"Tom","TimeSubmitted":"11/10/2011 4:00 PM"}}

The response I get from sending that request is 200, but when I then look at the Evals that have been saved, the one I just added has a valid Id, but Comment and Submitter are both null, and TimeSubmitted is 1/1/0001 12:00:00 AM.

It seems like WCF is getting the request, but is not deserializing the object correctly. But if that’s the case, I don’t know why it’s not throwing some sort of exception. Does it look like I’m doing this right, or am I missing something?

UPDATE: Here is the endpoint declaration in App.config:

 <endpoint binding="webHttpBinding" behaviorConfiguration="webHttp"
   contract="EvalServiceLibrary.IEvalService" />

And the endpoint behavior referred to:

<behavior name="webHttp">
  <webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
  • 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-05-26T22:15:22+00:00Added an answer on May 26, 2026 at 10:15 pm

    The default body style in the WebInvoke attribute is Bare, meaning that the object should be sent without a wrapper containing the object name:

    {"Comment":"testComment222",
     "Id":"doesntMatter",
     "Submitter":"Tom",
     "TimeSubmitted":"11/10/2011 4:00 PM"}
    

    Or you can set the request body style to Wrapped, and that would make the input require the wrapping {"eval"...} object:

    [OperationContract]
    [WebInvoke(RequestFormat=WebMessageFormat.Json,
       ResponseFormat=WebMessageFormat.Json,
       UriTemplate = "eval",
       BodyStyle = WebMessageBodyStyle.WrappedRequest)] // or .Wrapped
    void SubmitEval(Eval eval);
    

    Update: there’s another problem in your code, since you’re using DateTime, and the format expected by the WCF serializer for dates in JSON is something like \/Date(1234567890)\/. You can change your class to support the format you have by following the logic described at MSDN Link (fine-grained control of serialization format for primitives), and shown in the code below.

    public class StackOverflow_8086483
    {
        [DataContract]
        public class Eval //Models an evaluation
        {
            [DataMember]
            public string Id { get; set; }
    
            [DataMember]
            public string Submitter { get; set; }
    
            [DataMember]
            public string Comment { get; set; }
    
            [DataMember(Name = "TimeSubmitted")]
            private string timeSubmitted;
    
            public DateTime TimeSubmitted { get; set; }
    
            public override string ToString()
            {
                return string.Format("Eval[Id={0},Submitter={1},Comment={2},TimeSubmitted={3}]", Id, Submitter, Comment, TimeSubmitted);
            }
    
            [OnSerializing]
            void OnSerializing(StreamingContext context)
            {
                this.timeSubmitted = this.TimeSubmitted.ToString("MM/dd/yyyy h:mm tt", CultureInfo.InvariantCulture);
            }
    
            [OnDeserialized]
            void OnDeserialized(StreamingContext context)
            {
                DateTime value;
                if (DateTime.TryParseExact(this.timeSubmitted, "MM/dd/yyyy h:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None, out value))
                {
                    this.TimeSubmitted = value;
                }
            }
        }
    
        [ServiceContract]
        public interface IEvalService
        {
            [OperationContract]
            [WebInvoke(RequestFormat = WebMessageFormat.Json,
               ResponseFormat = WebMessageFormat.Json, UriTemplate = "eval",
               BodyStyle = WebMessageBodyStyle.Wrapped)]
            void SubmitEval(Eval eval);
        }
    
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
        class EvalService : IEvalService
        {
            public void SubmitEval(Eval eval)
            {
                Console.WriteLine("Received eval: {0}", eval);
            }
        }
    
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            WebServiceHost host = new WebServiceHost(typeof(EvalService), new Uri(baseAddress));
            host.Open();
            Console.WriteLine("Host opened");
    
            string data = "{\"eval\":{\"Comment\":\"testComment222\",\"Id\":\"doesntMatter\", \"Submitter\":\"Tom\",\"TimeSubmitted\":\"11/10/2011 4:00 PM\"}}";
            WebClient c = new WebClient();
            c.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
            c.UploadData(baseAddress + "/eval", Encoding.UTF8.GetBytes(data));
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.