Problems with PUT

Mar 22, 2011 at 10:59 PM
Edited Mar 23, 2011 at 2:42 PM


i try to execute using datajs version 0.0.2 the following javascript for an update:

var requestPut = {
    headers: { "DataServiceVersion": "2.0" },
    method: "PUT",  
    requestUri: "http://localhost:2976/WcfDataService1.svc/Machines(1)",
    data: {
        MachineName: 'Mixer'
but i get this error message: 
ErrorHTTP request failed - {"error": {"code": "", "message": {"lang": "en-GB", "value": "Error processing request stream. The property name 'results' specified for type 'DataModel.Machine' is not valid."}}}

The 'results' is there in the json request (seen with Fiddler)...


For some reason this results is handled as a property of my Machine entity.

On the same server, POST and DELETE work well for the same service:


public class WcfDataService1 : DataService<SdnODataEntities>
    public static void InitializeService(DataServiceConfiguration config)
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetEntitySetPageSize("*", 10);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
What could be wrong?
Mar 24, 2011 at 4:51 AM

svelde, this seems to be a problem with the JSON serializer. As a workaround, setting the DataServiceVersion header to "1.0" instead of "2.0" in your sample code should produce the right body - just let me know how this goes.

I'll be opening an issue to track this to a fix.

Thanks for reporting this!



Mar 24, 2011 at 4:53 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 24, 2011 at 7:51 PM

i have tried the same example with 1.0 but this gave an error in the end.

PUT http://localhost:2976/WcfDataService1.svc/Machines(1) HTTP/1.1
Content-Type: application/json
Accept-Language: nl,en-US;q=0.5
dataserviceversion: 1.0
Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, */*;q=0.1
Referer: http://localhost:2976/datajs_POST_HTMLPage.htm
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Host: localhost:2976
Content-Length: 23
Connection: Keep-Alive
Pragma: no-cache


The response is:

HTTP/1.1 500 Internal Server Error
Cache-Control: no-cache
Content-Length: 126
Content-Type: application/json
Server: Microsoft-IIS/7.5
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcU0RFXFN0YXJ0XE9EYXRhU3RhcnRTb2x1dGlvblxXZWJBcHBsaWNhdGlvbjJcV2NmRGF0YVNlcnZpY2UxLnN2Y1xNYWNoaW5lcygxKQ==?=
X-Powered-By: ASP.NET
Date: Thu, 24 Mar 2011 19:28:31 GMT

"error": {
"code": "", "message": {
"lang": "en-GB", "value": "An error occurred while processing this request."

The HTML is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >

    <title>Javascript Client Demo</title>

    <script type="text/javascript" src="Scripts\jquery-1.5.1.min.js"></script>
	<script type="text/javascript" src="Scripts\datajs-0.0.2.js"></script> 
	<script type="text/javascript" src="Scripts\JScriptDatajsPost.js"></script>    

    <div id="responsePlaceHolder">No results...</div>

    <script  type="text/javascript">
        $(document).ready(function () {

The javascript run is:

function PostRecords() {
    $("#responsePlaceHolder").html("<div>Posting To OData service...</div>");

    OData.defaultError = function (err) {
        $("#responsePlaceHolder").text("Error" + err.message + " - " + err.response.body);

    var requestPut = {
        headers: { "DataServiceVersion": "1.0" },
        method: "PUT",  
        requestUri: "http://localhost:2976/WcfDataService1.svc/Machines(1)",
        data: {
            MachineName: 'Mixer'
    OData.request(requestPut, SuccessSingle);

function SuccessSingle(data, response) {
    var html = "SUCCESS";


The service is:

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using ClassLibrary1;
using DataServicesJSONP;

namespace WebApplication2
public class WcfDataService1 : DataService<SdnODataEntities>
    public static void InitializeService(DataServiceConfiguration config)
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetEntitySetPageSize("*", 10);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
 Note the JSONPSupportbehaviour...

This runs in VS2010. The context is a EF4 context. The Database is Sql Server Express.

On the same service the DataJs Get, Post and Delete are working fine. Also with jquery I can Get and Post new records. And a windows console applca can change a record in the same context...

I try to write to a table:


CREATE TABLE [dbo].[Machines](
	[MachineId] [int] IDENTITY(1,1) NOT NULL,
	[MachineName] [nvarchar](50) NOT NULL,
	[SupervisorName] [nvarchar](50) NOT NULL,
	[Image] [image] NULL,
	[ImageName] [nvarchar](50) NULL,
	[MachineId] ASC
And the record is available in the database...
Any ideas?


<!-- $(document).ready(function () { PostRecords(); }); // -->


Mar 24, 2011 at 8:10 PM

From a first quick look, PUT implies replacing an entity with another one, so the missing properties are getting reset, which the database schema doesn’t seem to allow. If this is the case, changing PUT to MERGE would do the trick. Browsers may not allow the use of MERGE, so you can set up the request like this.

var request = {
  method: "POST",
  headers: {
    "X-HTTP-Method": "MERGE"

Also, you can get more details in the error by setting the UseVerboseErrors property to true on the configuration object during service initialization (be sure to turn it off after debugging though). This should help verify whether this is really a problem of trying to PUT an entity like that.


Mar 24, 2011 at 10:40 PM
Edited Mar 24, 2011 at 10:43 PM

Yes, this works better, nice.

Yes, merge should be a better description for the code i wanted to execute...

This is what i have seen now:

  • The UseVerboseErrors pointed me to the not null column "SupervisorName" which i did not fill in during the PUT.
  • The PUT works correct by filling in the correct values and setting NULL in all colums of which no value is passed.
  • The MERGE method functions well by just updating the correct columns in the record and not changing the other columns

This all works well for PUT and with DataServiceFunction set to 1.0 or leaving the header entry away. And this is also the case for the MERGE.

The DataServiceVersion set to 2.0 still gives the same error (as seen in the first post) in both situations.

I had looked at the Merge before but the usage of it was not clear to me in the documentation

I expected the merge to be like

    var requestPut = {
        method: "MERGE",
        requestUri: "http://localhost:2976/WcfDataService1.svc/Machines(33)",
        data: {
            MachineName: 'Mixer'
This is just a little bit more intuitive instead of X-HTTP-Method :-)
Thanks for the quick answers.
Mar 24, 2011 at 11:26 PM

I'm happy to have been able to help - I'll try and incorporate some of this in our documentation Wiki.

Just as a point of note, we had at some point considered allowing the syntax you mentioned, but unfortunately we can't detect automatically whether it's safe to do a MERGE or whether we should do a POST with the header instead. MERGE has the problem that many HTTP processors along the way may refuse to deal with it (including some browsers!), and POST has the problem that if the server isn't looking out for the header, we may do something different than what was intended or simply fail.

Our current thinking is that at some point we'll develop a higher-level API that is provides a per-site configuration point where apps can set which behavior they prefer, along with all other optional per-server capabilities that are hard or impossible to determine directly at runtime.

The DSV thing is just a bug we need to fix, hopefully we can get this resolved soon.

Thanks again for hanging on and all your valuable feedback!