cancel
Showing results for 
Search instead for 
Did you mean: 

Deep Insert with .NET Data Services

Former Member
0 Kudos

Hi experts,

I'm using "GWPAM add-in Visual Studio" to add reference for SAP NW Gateway service for C# code.

I was successfully with GET method, POST method with header level only.

But with complex business data (Header - Items) the add-in did not generate XML request that I desire.

I appreciate all your solutions.

Thank you.

Accepted Solutions (0)

Answers (1)

Answers (1)

showkath_naseem
Product and Topic Expert
Product and Topic Expert

Hi,

Internally we are using  .net WCF Data Services so I  would like to know exactly what is the real problem .


Please confirm if you’re trying same thing  “Created new project of type(C#) and adding proxy
using  “Add SAP Service Reference “feature from Visual Studio and you are performing  Create or Update operation  (?) in your application .

As per your comment get operation is working  for you also and your able to see complex types data.

I just tried  get operation  with below sample service

  https://vmw3815.wdf.sap.corp:44309/sap/opu/odata/sap/ZMATERIALS_DATA_SRV/Materials(1018)


This has complex type  “matpkgdata” ["ZMATERIALS_DATA_SRV.pkgmatdata]

The get operation sample code is as follows , as you said I am able to see complex types  with below
code.    


ZMATERIALS_DATA_SRV.ZMATERIALS_DATA_SRV serviceContext;


                string url =
  "https://vmw3815.wdf.sap.corp:44309/sap/opu/odata/sap/ZMATERIALS_DATA_SRV";


                string
  currentRequestString = string.Empty;


                ApplicationConfigReader.ConfigFilePath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;


                ServiceDetails
  serDetails = ConfigurationReaderHandler.Instance.GetServiceDetails("ZMATERIALS_DATA_SRV");


                this.serviceContext
  = new ZMATERIALS_DATA_SRV.ZMATERIALS_DATA_SRV(new
  Uri(url));


                ZMATERIALS_DATA_SRV.Material outputTest = new
  ZMATERIALS_DATA_SRV.Material();


                var
  material = (from cuurentMaterial in serviceContext.Materials


                                where cuurentMaterial.matid == 1018


                                select cuurentMaterial).FirstOrDefault(); ;


                outputTest.matid =
  material.matid;


                outputTest.description =
  material.description;


                outputTest.matpkgdata =
  material.matpkgdata;


If you confirm above points i.e are you using “Add SAP Service Reference” and Create/Update operations are not working  , then will try  to share one sample for you.

showkath_naseem
Product and Topic Expert
Product and Topic Expert
0 Kudos
  • For Deep insert using DataServiceContext is to  use Batch mode call

            serviceContext.SaveChanges(SaveChangesOptions.Batch),

          I have attached Fiddler Request and Response  for deep insert. 

          Please observe Fiddler , Our Proxy (SAP Reference )  how  generates XML  in single request.       

  • If you are looking  for header and related items  , then please use  .Expand()  causes related entities to be included inline in the response.
  • For Inserts call “serviceContext.AddRelatedObject(….)”.

I hope this information helps you......


 

POST
  https://vmw3815.wdf.sap.corp:44309/sap/opu/odata/sap/ZMATERIALS_DATA_SRV/$batch HTTP/1.1


 

User-Agent: Microsoft ADO.NET Data Services


 

DataServiceVersion: 1.0;NetFx


 

MaxDataServiceVersion: 2.0;NetFx


 

Accept-Language: en-US


 

sap-client:


 

RequestID: a8a7efbf98084757a4c8291ae07e677c


 

Authorization: Basic TmFzZWVtczpJbml0aWFsMQ==


 

x-requested-with: xmlhttprequest


 

X-CSRF-Token:


 

Accept: application/atom+xml,application/xml


 

Accept-Charset: UTF-8


 

Content-Type: multipart/mixed;
  boundary=batch_61329f02-367f-46bd-b5bd-80086c5ce1b4


 

Host: vmw3815.wdf.sap.corp:44309


 

Cookie: SAP_SESSIONID_G3T_100=lHxqL6CH9GlGEDo3AkJVu3xdJFPH_RHkgGkAUFa0PPA%3d;
  MYSAPSSO2=AjQxMDMBABhOAEEAUwBFAEUATQBTACAAIAAgACAAIAACAAYxADAAMAADABBHADMAVAAgACAAIAAgACAABAAYMgAwADEANQAwADMAMQAxADEANAA0ADcABQAEAAAACAYAAlgACQACRQD%2fATUwggExBgkqhkiG9w0BBwKgggEiMIIBHgIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYH%21MIH7AgEBMFAwRTELMAkGA1UEBhMCREUxDzANBgNVBAoTBlNBUC1BRzEMMAoGA1UECxMDRzNUMRcwFQYDVQQDDA4qLndkZi5zYXAuY29ycAIHIBQCAxAZATAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTUwMzExMTQ0NzA4WjAjBgkqhkiG9w0BCQQxFgQUxJ5Nr%2fI1nVDGxvS6nWDXM8U9vwkwCQYHKoZIzjgEAwQvMC0CFQCcndEJzH%21BawJfulu8hIPVoH8B1AIUJA8RdpcoqR4E%2f5jbv3bYtCmCQhw%3d


 

Content-Length: 3544


 

Expect: 100-continue


 


 

--batch_61329f02-367f-46bd-b5bd-80086c5ce1b4


 

Content-Type: multipart/mixed; boundary=changeset_553a6b61-0d22-4dfe-80dd-4dffc17f1ccd


 


 

--changeset_553a6b61-0d22-4dfe-80dd-4dffc17f1ccd


 

Content-Type: application/http


 

Content-Transfer-Encoding: binary


 


 

POST
  https://vmw3815.wdf.sap.corp:44309/sap/opu/odata/sap/ZMATERIALS_DATA_SRV/Materials
  HTTP/1.1


 

Content-ID: 1


 

Content-Type: application/atom+xml;type=entry


 

Content-Length: 1351


 


 

<?xml version="1.0" encoding="utf-8"
  standalone="yes"?>


 

<entry
  xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
  xmlns="http://www.w3.org/2005/Atom">


 

  <title />


 

  <author>


 

    <name />


 

  </author>


 


  <updated>2015-03-11T14:47:06.3061572Z</updated>


 

  <id />


 

  <content
  type="application/xml">


 

  
  <m:properties>


 

      <d:basicuom
  m:null="true" />


 

      <d:cdate
  m:type="Edm.DateTime">2012-01-29T00:00:00</d:cdate>


 

    
  <d:description>1032-Added on Mar 11 2015</d:description>


 

    
  <d:grossweight m:type="Edm.Decimal"
  m:null="true" />


 

    
  <d:matgrpcode m:null="true" />


 

    
  <d:matgrpdesc m:null="true" />


 

      <d:matid
  m:type="Edm.Int32">0</d:matid>


 

    
  <d:matpkgdata>


 

        <matgrppkg
  xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">1032-Test1
  Insert Added on Mar 11 2015</matgrppkg>


 

        <matrefpkg
  xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">1032-Test2
  Insert Added on Mar 11 2015</matrefpkg>


 

    
  </d:matpkgdata>


 

      <d:matstatus
  m:null="true" />


 

      <d:mattype
  m:null="true" />


 

      <d:mdate
  m:type="Edm.DateTime">2012-01-29T00:00:00</d:mdate>


 

      <d:netweight
  m:type="Edm.Decimal" m:null="true" />


 

    
  <d:weightunit m:null="true" />


 

  
  </m:properties>


 

  </content>


 

</entry>


 

--changeset_553a6b61-0d22-4dfe-80dd-4dffc17f1ccd


 

Content-Type: application/http


 

Content-Transfer-Encoding: binary


 


 

POST
  https://vmw3815.wdf.sap.corp:44309/sap/opu/odata/sap/ZMATERIALS_DATA_SRV/Materials
  HTTP/1.1


 

Content-ID: 2


 

Content-Type: application/atom+xml;type=entry


 

Content-Length: 1351


 


 

<?xml version="1.0" encoding="utf-8"
  standalone="yes"?>


 

<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
  xmlns="http://www.w3.org/2005/Atom">


 

  <title />


 

  <author>


 

    <name />


 

  </author>


 


  <updated>2015-03-11T14:47:06.3121572Z</updated>


 

  <id />


 

  <content
  type="application/xml">


 

  
  <m:properties>


 

      <d:basicuom
  m:null="true" />


 

      <d:cdate
  m:type="Edm.DateTime">2014-03-29T00:00:00</d:cdate>


 

    
  <d:description>1033-Added on Mar 11 2015</d:description>


 

    
  <d:grossweight m:type="Edm.Decimal"
  m:null="true" />


 

    
  <d:matgrpcode m:null="true" />


 

    
  <d:matgrpdesc m:null="true" />


 

      <d:matid
  m:type="Edm.Int32">0</d:matid>


 

    
  <d:matpkgdata>


 

        <matgrppkg
  xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">1033-Test1
  Insert Added on Mar 11 2015</matgrppkg>


 

        <matrefpkg
  xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">1033-Test2
  Insert Added on Mar 11 2015</matrefpkg>


 

    
  </d:matpkgdata>


 

      <d:matstatus
  m:null="true" />


 

      <d:mattype
  m:null="true" />


 

      <d:mdate
  m:type="Edm.DateTime">2014-03-29T00:00:00</d:mdate>


 

      <d:netweight
  m:type="Edm.Decimal" m:null="true" />


 

    
  <d:weightunit m:null="true" />


 

  
  </m:properties>


 

  </content>


 

</entry>


 

--changeset_553a6b61-0d22-4dfe-80dd-4dffc17f1ccd--


 

--batch_61329f02-367f-46bd-b5bd-80086c5ce1b4--


 


 


 


Regards,
Showkath.

Former Member
0 Kudos

First of all, thank you for your help.

I know Batch mode but it isn't what I need, because Batch just for multiple flat data.

For example, if you know PO (Purchase Order) in SAP you will see you can't use Batch to create a PO with multiple items.

More over, your Fiddler request is not a Deep insert case, it only create 2 Materials. Complex data as you mentioned in Fiddler request is just a way to group flat data into a structure.

I'm looking forward to hearing from you.

showkath_naseem
Product and Topic Expert
Product and Topic Expert
0 Kudos

I was initially confused when you said complex  object.

The only way to do deep insert using  DataServiceContext is to use Batch mode. While the OData protocol supports deep
insert, DataServiceContext (WCF DS) does not have that support in it.
For doing  Batch, call ctx.SaveChanges(SaveChangesOptions.Batch).

I added an answer below(#3).


#1 . Similar thread I have found  here :   http://scn.sap.com/thread/3169101

#2 . Deep Insert suggestion: Add-In returns xml ,Try to POST the same format that you would GET with $expand.

Using System.Data.Services.Client;

// ........
QueryOperationResponse<Z_PORDER_SRV.PurchaseOrderHeader> purchaseOrder=
serviceContext.PurchaseOrderHeaderCollection.
AddQueryOption("$filter","PONumber eq '1'")

   .Expand("PurchaseOrderItem").Execute()as QueryOperationResponse<Z_PORDER_SRV.PurchaseOrderHeader>;


Example :


<?xml
  version="1.0" encoding="UTF-8"?>


<atom:entry
  xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">


<atom:content
  type="application/xml">


<m:properties>


<d:TotalValueAtRelase>0.00</d:TotalValueAtRelase>


<d:PurchaseOrgGroup>AR1</d:PurchaseOrgGroup>


<d:PurchaseOrganization>7500</d:PurchaseOrganization>


<d:VendorAccountNumber>0000100073</d:VendorAccountNumber>


<d:PurchaseDocStatus>9</d:PurchaseDocStatus>


<d:PurchaseDocType>NB</d:PurchaseDocType>


<d:PurchaseDocCategory>F</d:PurchaseDocCategory>


<d:CompanyCode>7500</d:CompanyCode>


<d:PONumber>1</d:PONumber>


</m:properties>


</atom:content>


<atom:link
  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PurchaseOrderItem"
  type="application/atom+xml;type=feed" title="Z_PURCHASE_ORDER_SRV.PurchaseOrderHeader_PurchaseOrderItemCollection">


<m:inline>


<atom:feed>


<atom:entry>


<atom:content
  type="application/xml">


<m:properties>


<d:Plant>7500</d:Plant>



  <d:MaterialNumber>000000000000001108</d:MaterialNumber>


  <d:Material>000000000000001108</d:Material>


  <d:POItem>00001</d:POItem>


  <d:PONumber>0</d:PONumber>



  <d:MaterialType>ROH</d:MaterialType>


  <d:WeightUnit />



  <d:NetWeight>0.000</d:NetWeight>


  <d:NetValue>0.0000</d:NetValue>



  <d:GrossValue>11.2800</d:GrossValue>


  <d:PriceUnit>0</d:PriceUnit>


  <d:NetPrice>2.8200</d:NetPrice>



  <d:OrderPriceUnit>ST</d:OrderPriceUnit>


  <d:Unit>ST</d:Unit>


  <d:Quantity>4.000</d:Quantity>



  <d:TargetQuantity>0.000</d:TargetQuantity>


  <d:MaterialGroup>001</d:MaterialGroup>


</m:properties>


</atom:content>


</atom:entry>


</atom:feed>


</m:inline>


</atom:link>


</atom:entry>


#3 . Deep insert using  DataServiceContext  : The only way to do deep insert using  DataServiceContext is to use Batch mode. While the OData protocol supports deepinsert, DataServiceContext does not have that support in it.


Z_PORDER_SRV.PurchaseOrderHeader newPOHeader = new Z_PORDER_SRV.PurchaseOrderHeader();


            List<Z_PORDER_SRV.PurchaseOrderItem> newPOitems =
  GetNewPurchaseOrderItems(newPOHeader);


            foreach
  (Z_PORDER_SRV.PurchaseOrderItem newPOItem in newPOitems)


            {


                serviceContext.AddRelatedObject(newPOHeader, "PurchaseOrderItem",
  newPOItem);


                newPOHeader.PurchaseOrderItem.Add(newPOItem);


              
  newPOItem.PurchaseOrderHeader = newPOHeader;


            }


             serviceContext.SaveChanges(SaveChangesOptions.Batch);


But as you said  deep insert seems a cleaner approach to me, as the issue of dealing with the new parent key value can presumably be dealt with by the  controller action method.


#4 . Have a  look here :

How do I update an OData entity and modify its
navigation properties in one request?

#5.  You can make use of .net libraries available.  Libraries | Open Data Protocol

  http://scn.sap.com/thread/3535275

#6.  Create a sales order using the deep insert create request
with ODataModel
in  SAP UI5
application

http://scn.sap.com/community/developer-center/front-end/blog/2014/03/27/create-a-sales-order-using-t...

#7. You could refer to this link for this part of the OData spec.

OData Version 4.0 Part 1: Protocol

Hope this helps.


Regards,

Showkath Naseem.