Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is in the url of the inner request. The url needs to be relative to the host. Let's say your service is hosted in <code>host/service</code> (in our case, service will be the equivalent as the odata prefix), so normally you send requests like <code>host/service/Customers</code> or <code>/service/Customers</code>. </p> <p>When you issue a batch request, the urls in the inner requests might be absolute or relative to the host. The problem is that in your request, the url is <code>ServiceMetadatas</code> which is relative to the service root, not the host.</p> <p>Web API is interpreting the relative url as <code>host/ServiceMetadatas</code> instead of as <code>host/service/ServiceMetadatas</code> and that's what causes the error.</p> <p>Based on your repro project, the following request works fine:</p> <pre><code>POST http://localhost:6974/odata/$batch HTTP/1.1 Host: localhost:6974 User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0 Accept: multipart/mixed Accept-Language: he-IL,he;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate DataServiceVersion: 2.0 Content-Type: multipart/mixed; charset=UTF-8;boundary=batch_4f09-d7cf-dd99 MaxDataServiceVersion: 2.0 Referer: http://localhost:9000/ Content-Length: 565 Origin: http://localhost:9000 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache --batch_4f09-d7cf-dd99 Content-Type: multipart/mixed; boundary=changeset_ca0c-06b7-ddbe --changeset_ca0c-06b7-ddbe Content-Type: application/http Content-Transfer-Encoding: binary POST odata/ServiceMetadatas HTTP/1.1 Content-ID: 1 DataServiceVersion: 2.0 Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1 Content-Type: application/json;odata=verbose MaxDataServiceVersion: 2.0 {"ServiceMetadataId":-1,"ServiceName":"sdf sdf","Description":"sd fgs df"} --changeset_ca0c-06b7-ddbe-- --batch_4f09-d7cf-dd99-- </code></pre> <p>The associated response is the following one:</p> <pre><code>HTTP/1.1 202 Accepted Cache-Control: no-cache Pragma: no-cache Content-Type: multipart/mixed; boundary=batchresponse_6779b5e5-6e40-4363-9a98-5a33d062da28 Expires: -1 Server: Microsoft-IIS/8.0 DataServiceVersion: 2.0 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcamFjYWx2YXJcRG93bmxvYWRzXE9EYXRhQmF0Y2gtbWFzdGVyXENsZWFuV2ViQXBpUHJvamVjdFxvZGF0YVwkYmF0Y2g=?= X-Powered-By: ASP.NET Date: Tue, 17 Sep 2013 16:48:50 GMT Content-Length: 872 --batchresponse_6779b5e5-6e40-4363-9a98-5a33d062da28 Content-Type: multipart/mixed; boundary=changesetresponse_b63ca946-ce66-43e6-a78f-d44a5b8f2d5c --changesetresponse_b63ca946-ce66-43e6-a78f-d44a5b8f2d5c Content-Type: application/http Content-Transfer-Encoding: binary HTTP/1.1 201 Created Location: http://localhost:6974/odata/ServiceMetadatas(-1) Content-ID: 1 Content-Type: application/json; odata=verbose; charset=utf-8 DataServiceVersion: 2.0 { "d":{ "__metadata":{ "id":"http://localhost:6974/odata/ServiceMetadatas(-1)","uri":"http://localhost:6974/odata/ServiceMetadatas(-1)","type":"CleanWebApiProject.Models.ServiceMetadata" },"ServiceMetadataId":-1,"ServiceName":"sdf sdf","Description":"sd fgs df" } } --changesetresponse_b63ca946-ce66-43e6-a78f-d44a5b8f2d5c-- --batchresponse_6779b5e5-6e40-4363-9a98-5a33d062da28-- </code></pre> <p>The only change that I made in the controller is the following (and not related to batch):</p> <pre><code>public class ServiceMetadatasController : EntitySetController&lt;ServiceMetadata, int&gt; { protected override ServiceMetadata CreateEntity(ServiceMetadata entity) { return entity; } protected override int GetKey(ServiceMetadata entity) { return entity.ServiceMetadataId; } public override IQueryable&lt;ServiceMetadata&gt; Get() { return new List&lt;ServiceMetadata&gt; { new ServiceMetadata() {ServiceName = "Service1", Description = "Desc1"}, new ServiceMetadata() {ServiceName = "Service2", Description = "Desc1"} }.AsQueryable(); } } </code></pre> <p>I hope this solves your problem, also let me know if you are generating the url for the inner request manually or if it's breezejs doing it for you, so that I can follow up and make sure it gets fixed.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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