JayData. OData v.3 Action POST parameters received as null

1.1k Views Asked by At

My OData POST Action receive the parameters as null because it gets them from JayData client as part of the body and is expecting them as part of the URI.

I have created an OData service based in WCF Data Services 5.6.0 and Llblgen Pro 4.0 (simply the best .Net ORM out there right now). It has a POST Action:

[WebInvoke(Method = "POST")]
public void DeletePeople(string guidsToDelete) {...}

The OData v.3 standard does not support passing parameters to POST actions as part of the body, but expect them to be in the queryString part of the URI. That is, in System.Data.Services.Client, you have to set them as UriOperationParameter instead of BodyOperationParameter.

Can I configure in JayData's ServiceOperation definition where to send the parameters, or must I assume it does not support POST with parameters right now?

// This works, of course :-)
// JayData client. EntityContext definitions. Changed to GET instead of POST
'DeletePeople': { type: $data.ServiceOperation, method: 'GET', params: [{ name: 'guidsToDelete', type: 'Edm.String' }] }

// Updated server operation (not action any more):
[WebGet]
public void DeletePeople(string guidsToDelete)

TIA,

Raist

2

There are 2 best solutions below

2
On

JayData expects service operations published via WebGet attribute right now. You are right about the OData standard, it does expecti the params of POST operations in URL parameter, but it's strange because both classic WCF and WebAPI uses params in the body... it's a standard, so it must be followed. In case you cannot use WebGet attribute, feel free to propose the feature that supports POST invoke method:

2
On

I think you are confusing Actions with Service Operations.

Actions may have a side effect, service operations must not have a side effect. Service Operations are marked as a legacy feature in OData v3.0, as Functions can achieve the same result. Note that Functions do not use POST - they must use the GET method and therefore pass any parameters in the query string.

You are best to refer to the protocol specification document which is the complete specification (the online content is not complete).

According to the OData v3.0 specification, any parameters associated with an action are passed in the request body (not request URI), using the POST method. Here's the action example from the specification document:

HTTP Request:

POST /Customers('ALFKI')/SampleEntities.CreateOrder HTTP/1.1 Host: host
Content-Type: application/json;odata=verbose DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
If-Match: ...ETag...
Content-Length: ####
{
   "quantity": 2,
   "discountCode": "BLACKFRIDAY" 
}

HTTP Response:

HTTP/1.1 204 OK
Date: Fri, 11 Oct 2008 04:23:49 GMT