Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

New Post: Odata batch issue - with nightly

$
0
0
Hi, I've figured out the problem, it was simpler than I thought. I assume you have built this request manually on fiddler or with any other utility, am I correct?

The problem is that the verb used for creating an entry is POST, not PUT, so either your verb is wrong in this request (it should be POST) or your url is wrong on the request and should be /odata/Incidents(500) (in that case you should also implement UpdateEntity in EntitySetController. I strongly encourage you to use WCF Data Services client or any OData client to test your services:

You only need to create a console app, start the service without debugging (CTRL+F5), right click on add service reference on the project you just created, point it to your OData Service url and it will generate an OData client.

You can then write code like the following:
            Container container = new Container(new Uri("http://localhost.fiddler:64630/odata"));
            container.AddToIncidents(new Incident() { IncidentID = 500, Name = "Incident name" });
            container.SaveChanges(SaveChangesOptions.Batch);

            Container newContainer = new Container(new Uri("http://localhost.fiddler:64630/odata"));
            Incident incident = newContainer.Incidents.Where(i => i.IncidentID == 500).ToList().Single();
            incident.Name = "Updated incident name";
            newContainer.UpdateObject(incident);
            newContainer.SaveChanges(SaveChangesOptions.Batch | SaveChangesOptions.ReplaceOnUpdate);
Here are the batch requests that I've created using the client and the associated responses, (forget about the .fiddler in the urls, that is just a trick to make sure the requests go trough fiddler):

Batch request creating an entry:
POST http://localhost:64630/odata/$batch HTTP/1.1
User-Agent: Microsoft ADO.NET Data Services
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: multipart/mixed
Accept-Charset: UTF-8
Content-Type: multipart/mixed; boundary=batch_bf8a41b0-f692-44d1-a355-161e7e81cd97
Host: localhost:64630
Content-Length: 1186
Expect: 100-continue
Connection: Keep-Alive

--batch_bf8a41b0-f692-44d1-a355-161e7e81cd97
Content-Type: multipart/mixed; boundary=changeset_d1cf49c0-3a0c-4c9a-a9d4-38cfa4865d8c

--changeset_d1cf49c0-3a0c-4c9a-a9d4-38cfa4865d8c
Content-Type: application/http
Content-Transfer-Encoding: binary

POST http://localhost.fiddler:64630/odata/Incidents HTTP/1.1
Content-ID: 1
Content-Type: application/atom+xml
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8

<?xml version="1.0" encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><category term="BatchIssueProject.Models.Incident" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><id /><title /><updated>2013-05-28T16:49:53Z</updated><author><name /></author><content type="application/xml"><m:properties><d:IncidentID m:type="Edm.Int32">500</d:IncidentID><d:Name>Incident name</d:Name></m:properties></content></entry>
--changeset_d1cf49c0-3a0c-4c9a-a9d4-38cfa4865d8c--
--batch_bf8a41b0-f692-44d1-a355-161e7e81cd97--
Response:
HTTP/1.1 202 Accepted
Cache-Control: no-cache
Pragma: no-cache
Content-Type: multipart/mixed; boundary=batchresponse_d1e737c1-04b0-4cf2-8737-8b53c23573a7
Expires: -1
Server: Microsoft-IIS/8.0
DataServiceVersion: 3.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcamFjYWx2YXJcRG93bmxvYWRzXEJhdGNoSXNzdWVQcm9qZWN0XEJhdGNoSXNzdWVQcm9qZWN0XG9kYXRhXCRiYXRjaA==?=
X-Powered-By: ASP.NET
Date: Tue, 28 May 2013 16:49:54 GMT
Content-Length: 1575

--batchresponse_d1e737c1-04b0-4cf2-8737-8b53c23573a7
Content-Type: multipart/mixed; boundary=changesetresponse_b5e7a26f-2329-4b3d-baf3-9b16c5d28b9d

--changesetresponse_b5e7a26f-2329-4b3d-baf3-9b16c5d28b9d
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 201 Created
Location: http://localhost.fiddler:64630/odata/Incidents(500)
Content-ID: 1
Content-Type: application/atom+xml; charset=utf-8
DataServiceVersion: 3.0

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://localhost.fiddler:64630/odata/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
  <id>http://localhost.fiddler:64630/odata/Incidents(500)</id>
  <category term="BatchIssueProject.Models.Incident" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <link rel="edit" href="http://localhost.fiddler:64630/odata/Incidents(500)" />
  <link rel="self" href="http://localhost.fiddler:64630/odata/Incidents(500)" />
  <title />
  <updated>2013-05-28T16:49:54Z</updated>
  <author>
    <name />
  </author>
  <content type="application/xml">
    <m:properties>
      <d:IncidentID m:type="Edm.Int32">500</d:IncidentID>
      <d:Name>Incident name</d:Name>
    </m:properties>
  </content>
</entry>
--changesetresponse_b5e7a26f-2329-4b3d-baf3-9b16c5d28b9d--
--batchresponse_d1e737c1-04b0-4cf2-8737-8b53c23573a7--
Batch request updating the same entry:
POST http://localhost:64630/odata/$batch HTTP/1.1
User-Agent: Microsoft ADO.NET Data Services
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: multipart/mixed
Accept-Charset: UTF-8
Content-Type: multipart/mixed; boundary=batch_389f67d4-512f-4cb2-a692-f16f48bcdcb5
Host: localhost:64630
Content-Length: 1236
Expect: 100-continue

--batch_389f67d4-512f-4cb2-a692-f16f48bcdcb5
Content-Type: multipart/mixed; boundary=changeset_5f3f1fc4-0c79-40b5-8235-9a80159d9fd3

--changeset_5f3f1fc4-0c79-40b5-8235-9a80159d9fd3
Content-Type: application/http
Content-Transfer-Encoding: binary

PUT http://localhost:64630/odata/Incidents(500) HTTP/1.1
Content-ID: 2
Content-Type: application/atom+xml
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8

<?xml version="1.0" encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><id>http://localhost:64630/odata/Incidents(500)</id><category term="BatchIssueProject.Models.Incident" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><title /><updated>2013-05-28T16:49:54Z</updated><author><name /></author><content type="application/xml"><m:properties><d:IncidentID m:type="Edm.Int32">500</d:IncidentID><d:Name>Updated incident name</d:Name></m:properties></content></entry>
--changeset_5f3f1fc4-0c79-40b5-8235-9a80159d9fd3--
--batch_389f67d4-512f-4cb2-a692-f16f48bcdcb5--
Response
HTTP/1.1 202 Accepted
Cache-Control: no-cache
Pragma: no-cache
Content-Type: multipart/mixed; boundary=batchresponse_f0993a32-f104-41f1-9c40-c566b2962aa7
Expires: -1
Server: Microsoft-IIS/8.0
DataServiceVersion: 3.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcamFjYWx2YXJcRG93bmxvYWRzXEJhdGNoSXNzdWVQcm9qZWN0XEJhdGNoSXNzdWVQcm9qZWN0XG9kYXRhXCRiYXRjaA==?=
X-Powered-By: ASP.NET
Date: Tue, 28 May 2013 16:49:54 GMT
Content-Length: 439

--batchresponse_f0993a32-f104-41f1-9c40-c566b2962aa7
Content-Type: multipart/mixed; boundary=changesetresponse_da4d5a22-4f2f-4706-983f-c8e5ff83970f

--changesetresponse_da4d5a22-4f2f-4706-983f-c8e5ff83970f
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 204 No Content
Content-ID: 2


--changesetresponse_da4d5a22-4f2f-4706-983f-c8e5ff83970f--
--batchresponse_f0993a32-f104-41f1-9c40-c566b2962aa7--

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>