Note that there are some explanatory texts on larger screens.

plurals
  1. POPost batch request with Breezejs
    primarykey
    data
    text
    <p>I've been trying to POST an entity using Breezejs and WebAPI OData Controllers. <br/>Here are the configurations:</p> <pre><code>config.Routes.MapODataRoute( routeName: "odata", routePrefix: "odata", model: model, batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)); </code></pre> <p>Where the model is very straight forward:</p> <pre><code>public class ServiceMetadata { public int ServiceMetadataId { get; set; } public string ServiceName { get; set; } public string Description { get; set; } public ObjectState? State { get; set; } public DateTime? LastUpdated { get; set; } } </code></pre> <p>And it is mapped through the default:</p> <pre><code>ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); </code></pre> <p><strong>The Client</strong> is also very simple taken using AngularJs and partially from the Todo example: <a href="http://www.breezejs.com/samples/todo-angular" rel="nofollow">http://www.breezejs.com/samples/todo-angular</a> </p> <pre><code>breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true); var serviceName = 'http://localhost:8081/odata/'; breeze.config.initializeAdapterInstances({ dataService: "OData" }); var manager = new breeze.EntityManager(serviceName); manager.enableSaveQueuing(true); </code></pre> <p>The actual Posting is done using the default createEntity() method:</p> <pre><code>function createServiceMetadata(initialValues) { return manager.createEntity('ServiceMetadata', initialValues); } </code></pre> <p>And the whole thing looks like:</p> <pre><code> serviceMetadatas.createServiceMetadata({ ServiceName: $scope.newServiceName, Description: $scope.newServiceDescription }); serviceMetadatas.saveChanges(); </code></pre> <p><br/> However, the request is not being transferred to the correct controller (ServiceMetadatasController which inherits from EntitySetController), or any other controller for that matter. <br/> The HTTP request looks like this:</p> <pre><code> POST http://localhost:8081/odata/$batch HTTP/1.1 Host: localhost:8081 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: 580 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 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","LastUpdated":null} --changeset_ca0c-06b7-ddbe-- --batch_4f09-d7cf-dd99-- </code></pre> <p>And the response:</p> <pre><code> HTTP/1.1 202 Accepted Cache-Control: no-cache Pragma: no-cache Content-Type: multipart/mixed; boundary=batchresponse_966d4460-e00e-4900-b1c9-85b17081cfac Expires: -1 Server: Microsoft-IIS/8.0 Access-Control-Allow-Origin: http://localhost:9000 Access-Control-Allow-Credentials: true DataServiceVersion: 2.0 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcVG9tZXJcRG9jdW1lbnRzXFZpc3VhbCBTdHVkaW8gMjAxMlxQcm9qZWN0c1xFYXN5Qml6eVxFYXN5Qml6eS5XZWJBUElcb2RhdGFcJGJhdGNo?= X-Powered-By: ASP.NET Date: Sun, 15 Sep 2013 14:32:39 GMT Content-Length: 443 --batchresponse_966d4460-e00e-4900-b1c9-85b17081cfac Content-Type: multipart/mixed; boundary=changesetresponse_44da5dcf-877d-4041-a82b-c51d06a4e9a4 --changesetresponse_44da5dcf-877d-4041-a82b-c51d06a4e9a4 Content-Type: application/http Content-Transfer-Encoding: binary HTTP/1.1 406 Not Acceptable Content-ID: 1 --changesetresponse_44da5dcf-877d-4041-a82b-c51d06a4e9a4-- --batchresponse_966d4460-e00e-4900-b1c9-85b17081cfac-- </code></pre> <p>Any idea what the hack is going on? B.T.W GET requests works great.</p> <p>P.S. After looking at couple of demos, I though the using BreezeJS will be straight forward considering WebApi and OData.<br/> I must say it is <strong>Far</strong> from being easy to configure this JS library. I hope it will turn out to be hard-to-setup but easy-to-use.</p> <p>Thanks.</p> <p><strong>@UPDATE</strong> See <strong>Javier</strong>'s great answer!!</p> <p>In after digging allllot on the breeze code, I came to realize that the problem is laying deep in the createChangeRequests() of breezejs, right here:</p> <pre><code>request.requestUri = entity.entityType.defaultResourceName; </code></pre> <p>Where for some reason the defaultResouceName, completely ignores the path to this entity. Long story short, the following is a hack to resolve:</p> <pre><code>manager.metadataStore.getEntityType(ENTITY_TYPE).setProperties({defaultResourceName: THE_MISSING_PART_FROM_THE_URL + ENTITY_TYPE}); manager.createEntity(ENTITY_TYPE, values); </code></pre> <p>Not very nice, but still works!</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