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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:55:10+00:00 2026-05-13T21:55:10+00:00

I am attempting to create and host a simple RESTful WCF Service. The service

  • 0

I am attempting to create and host a simple RESTful WCF Service. The service works perfectly except for 1 situation. I attempt to perform a POST to insert a new object into my static List using the JSON request of:

{"sampleItem":{"Id":1,"StartValue":2,"EndValue":3}}

If I then change the request to be:

{"sampleItemBlah":{"Id":1,"StartValue":2,"EndValue":3}}

I get a 500 response and all future POST’s return a 500 error until I recycle my IIS App Pool and then it starts to work again.

It doesn’t appear that the service is in a faulted state because I can still perform GET’s and get data back. I turned on trace debugging and I do not see any errors in my log file.

Does anyone have any ideas?

Here is my Service Contract:

[ServiceContract]
public interface IWcfRestService
{
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    SampleItem Insert(SampleItem sampleItem);
}

[DataContract]
public class SampleItem
{
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public int StartValue { get; set; }
    [DataMember]
    public int EndValue { get; set; }
}

And here is my implementation:

public class WcfRestService : IWcfRestService
{
    private static readonly List<SampleItem> Items = new List<SampleItem>();

    public SampleItem Insert(SampleItem sampleItem)
    {
        return BaseInsert(sampleItem);
    }

    private static SampleItem BaseInsert(SampleItem sampleItem)
    {
        if (Items.Exists(x => x.Id == sampleItem.Id))
            Items.RemoveAll(x => x.Id == sampleItem.Id);

        Items.Add(sampleItem);

        return sampleItem;
    }
}

And finally here is my ServiceModel section of my Web.config:

<services>
  <service behaviorConfiguration="Services.ServiceBehavior" 
           name="WcfRestServiceApp.WcfRestService">
    <endpoint address="" 
              behaviorConfiguration="RESTBehavior" 
              binding="webHttpBinding"
              contract="WcfRestServiceApp.IWcfRestService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="RESTBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="Services.ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Any and all help is greatly appreciated.

  • 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-13T21:55:10+00:00Added an answer on May 13, 2026 at 9:55 pm

    It turned out that the problem was with using the tag:

    BodyStyle = WebMessageBodyStyle.Wrapped
    

    When I removed it, the requirement to have:

    {"sampleItem":{"Id":1,"StartValue":2,"EndValue":3}}
    

    turned into:

    {"Id":1,"StartValue":2,"EndValue":3}
    

    This forced the cast to the correct object type and if the field wasn’t present, it set the value to null or the type’s default empty value.

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

Sidebar

Related Questions

I'm trying to host a WCF service in IIS7 that works with both Silverlight
I'm attempting to create a WCF service where several thousand (~10,000) clients can connect
I am trying to create a WCF web service which will allow other applications
I am attempting to host a service that serves up basic web content (HTML,
Attempting to run this SQL: DELIMITER $$ CREATE TRIGGER crypt_f BEFORE INSERT ON c_data_test
While attempting to create a replacement tablespace for USER, I accidentally created a datafile
Im attempting to create a new operator :? on lists, which operates the same
I attempting to create an 800x500 div with four overlapping divs inside the container
I attempting to create custom tabs using this . But when I try to
I'm attempting to create a table for monitoring purposes using the following script: $w3wppriv

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.