Note that there are some explanatory texts on larger screens.

plurals
  1. POBad Request to RESTful WCF Service Forces IIS to Recycle App Pool
    primarykey
    data
    text
    <p>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:</p> <pre><code>{"sampleItem":{"Id":1,"StartValue":2,"EndValue":3}} </code></pre> <p>If I then change the request to be:</p> <pre><code>{"sampleItemBlah":{"Id":1,"StartValue":2,"EndValue":3}} </code></pre> <p>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.</p> <p>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.</p> <p>Does anyone have any ideas?</p> <p>Here is my Service Contract:</p> <pre><code>[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; } } </code></pre> <p>And here is my implementation:</p> <pre><code>public class WcfRestService : IWcfRestService { private static readonly List&lt;SampleItem&gt; Items = new List&lt;SampleItem&gt;(); public SampleItem Insert(SampleItem sampleItem) { return BaseInsert(sampleItem); } private static SampleItem BaseInsert(SampleItem sampleItem) { if (Items.Exists(x =&gt; x.Id == sampleItem.Id)) Items.RemoveAll(x =&gt; x.Id == sampleItem.Id); Items.Add(sampleItem); return sampleItem; } } </code></pre> <p>And finally here is my ServiceModel section of my Web.config:</p> <pre><code>&lt;services&gt; &lt;service behaviorConfiguration="Services.ServiceBehavior" name="WcfRestServiceApp.WcfRestService"&gt; &lt;endpoint address="" behaviorConfiguration="RESTBehavior" binding="webHttpBinding" contract="WcfRestServiceApp.IWcfRestService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="RESTBehavior"&gt; &lt;webHttp /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="Services.ServiceBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; </code></pre> <p>Any and all help is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload