How can I make OData Batch Request with multiple operations on multiple entity sets.
<service_data>
<post>
<category>
<id>3</id>
<name>NewCategoryName</name>
</category>
</post>
<put>
<supplier>
<id>1</id>
<name>ChangedSupplierName</name>
<address>
<street>Whitefield</street>
<city>Bangalore</city>
<state>Karnataka</state>
<zipcode>560066</zipcode>
<country>INDIA</country>
</address>
</supplier>
</put>
<merge>
<product>
<id>2</id>
<rating>4</rating>
<price>24</price>
</product>
</merge>
</service_data>
This single payload contains the data for all three entity sets i.e. Products, Categories and Suppliers.
Then use Parallel Multicast(as order doesn't matter in this scenario), with three branches to get the batch request compliant payload for each entity set and operation
In each branch we use Message Mapping with initial payload XSD as the source and XSD of each batch operation as the target to get the batch request compliant payload for each entity set and operation
Initial Payload XSD
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="service_data">
<xs:complexType>
<xs:sequence>
<xs:element name="post">
<xs:complexType>
<xs:sequence>
<xs:element name="category">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="id"/>
<xs:element type="xs:string" name="name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="put">
<xs:complexType>
<xs:sequence>
<xs:element name="supplier">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="id"/>
<xs:element type="xs:string" name="name"/>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="street"/>
<xs:element type="xs:string" name="city"/>
<xs:element type="xs:string" name="state"/>
<xs:element type="xs:int" name="zipcode"/>
<xs:element type="xs:string" name="country"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="merge">
<xs:complexType>
<xs:sequence>
<xs:element name="product">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="id"/>
<xs:element type="xs:byte" name="rating"/>
<xs:element type="xs:byte" name="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Hint: To get the XSD of each batch operation along with the entity set and it's properties, configure OData Adapter one by one for:
a. POST on Categories,
b. PUT on Suppliers, and
c. MERGE on Products
<batchParts>
<batchChangeSet>
<batchChangeSetPart>
<method>POST</method>
<Categories>
<Category>
<ID>3</ID>
<Name>NewCategoryName</Name>
</Category>
</Categories>
</batchChangeSetPart>
<batchChangeSetPart>
<method>PUT</method>
<headers>
<header>
<headerName>If-Match</headerName>
<headerValue>W/"0"</headerValue>
</header>
</headers>
<Suppliers>
<Supplier>
<ID>1</ID>
<Name>ChangedSupplierName</Name>
<Address>
<Street>Whitefield</Street>
<City>Bangalore</City>
<State>Karnataka</State>
<ZipCode>560066</ZipCode>
<Country>INDIA</Country>
</Address>
</Supplier>
</Suppliers>
</batchChangeSetPart>
<batchChangeSetPart>
<method>MERGE</method>
<Products>
<Product>
<ID>2</ID>
<Rating>4</Rating>
<Price>24</Price>
</Product>
</Products>
</batchChangeSetPart>
</batchChangeSet>
</batchParts>
Then call the OData endpoint using OData Adapter using Request-Reply flow step.
Important Note: The OData Adapter can be configured with any batch operation. In design time selecting a particular entity set and batch operation doesn't matter as the call will happen based on the previous cumulative batch request payload.
<batchPartResponse>
<batchChangeSetResponse>
<batchChangeSetPartResponse>
<headers>
<Accept-Language></Accept-Language>
<DataServiceVersion>1.0;</DataServiceVersion>
<Accept></Accept>
<Cache-Control>no-cache</Cache-Control>
</headers>
<statusCode>204</statusCode>
<body/>
<contentId/>
<statusInfo>No Content</statusInfo>
</batchChangeSetPartResponse>
</batchChangeSetResponse>
</batchPartResponse>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
14 | |
13 | |
13 | |
12 | |
8 | |
8 | |
7 | |
6 | |
5 |