How can I use DataServiceContext to call an unbound action accepting an entity-reference parameter?

225 Views Asked by At

My OData v4 client uses generated classes based on the 6.x version of Microsoft.OData.Client.

Now it needs to call an action with the following definition:

  <Action Name="Resolve">
    <Parameter Name="CertRequestEntity" Type="CertificationRequest" />
    <Parameter Name="CertRequestId" Type="Edm.String" Nullable="false" Unicode="false" />
    <Parameter Name="RequestSuccess" Type="Edm.Boolean" Nullable="false" />
    <Parameter Name="RejectedMessage" Type="Edm.String" Unicode="false" />
  </Action>

It is easy to construct primitive parameters with the aid of the BodyOperationParameter class, but I cannot find any documentation on the proper way to construct an entity reference as a parameter. Is this possible? (I ended up using HttpClient with a hand-rolled JSON body.)

1

There are 1 best solutions below

1
On

Note that the definition above, as written, is invalid; the type of the first parameter should be namespace qualified.

If you have control over the schema, the simplest solution would be to make this a bound action (IsBound="true" on the action definition). Bound actions are similar to extension methods in .NET -- the first (entity) parameter becomes the "binding parameter", and you would call the action by appending the action name (/Resolve) to the URL for the CertificationRequest that you wanted to resolve, passing the remaining (non-binding) parameters in the body.