cancel
Showing results for 
Search instead for 
Did you mean: 

Deep Insert with .NET Data Services

Former Member
0 Kudos

Just wondering if anyone has had any success doing a create deep insert using .NET Data Services? I am able to do everything else I've tried (querying, reading, create simple entities) but unable to create complex objects with deep insert using built in functionality.

The only way I have been able to do it is build up the XML payload manually and push that to the GW server. This does work, however it's very sloppy and has no validation as it is all free form XML.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mike,

Are you using the .NET OData SDK to create semantic proxies to consume the Gatewy service?

Because when we worked with these proxies, we were able to create complex objects with deep insert without the need to create the XML payload ourselves.

In addition, I work in the team that has developed the SAP NetWeaver Gateway® developer tool for Visual Studio (download), which is an Visual Studio 2010 Add-on that leverages the OData SDK to generate proxies that connect to Gateway, adding support to sap-labels, connectivity helpers and some additional Gateway related features.

If you use one of these options, we will be able to guide you by code how to perform the deep insert operations.

Thanks,

Maxim

Former Member
0 Kudos

Hi Maxim,


I'm using the .NET data services client libraries built into the 4.0 framework...is there another set of libraries we should be using? I didn't know there was a specific SDK for OData. Can you provide a link to this?

We had tried the VS gateway tool initially, but it didn't really fit with us.

If you can provide the link and even a sample of the deep insert, that would be great.

Cheers,

Mike

Former Member
0 Kudos

Hi Maxim,


Any update on this? Would love any additional info.

Thanks,
Mike

Former Member
0 Kudos

Hi Mike,

I regret to inform you that the .NET proxies do not support Deep Insert as I've initially thought.

After testing again the same solution that made me believe Deep Insert is supported, I've found that it must have been a not standard implementation of the service that allowed this.

On a regular service, the XML that is sent by the .NET proxies doesn't support Deep Insert.

Best Regards,

Maxim

Former Member
0 Kudos

Hi Maxim,

To this I would like to ask, if the implementation is possible using the Gateway Developer tool?

We have created a Gateway service that allows us to create a Sales Order with multiple items. How do I do this implementation in .NET, so that I can create a service which creates the sales order (header + items) and POSTs it to SAP?

For now, I tried with the following code:


class Program

    {

        static string csrfToken = "";

        static string setCookie = "";

        static CookieContainer cookieJar;

        static void Main(string[] args)

        {

            string s = "2002-06-14" + "T00:00:00";

            DateTime d = Convert.ToDateTime(s);

            string serviceUrl = "http://<server>:<port>/sap/opu/odata/sap/SALESORDER03";

            SALESORDER03.SALESORDER03 service = new SALESORDER03.SALESORDER03(new Uri(serviceUrl));

            SALESORDER03.SOItem so_item = new SALESORDER03.SOItem()

            {

                OrderId = "",

                Item = "000010",

                Material = "MP_SHEET_22",

                Description = "Sheet Grade B, BWT 20lb/75gsm",

                Plant = "M210",

                Quantity = (decimal)25000.000,

                UoM = "LBR",

                Value = (decimal)10723.70,

            };

            SALESORDER03.SOHeader so_header = new SALESORDER03.SOHeader()

            {

                OrderId = "",

                DocumentType = "MOR",

                DocumentDate = d,

                CustomerId = "MP-CUST201",

                SalesOrg = "M210",

                DistChannel = "01",

                Division = "M1",

                OrderValue = (decimal)10723.70,

                Currency = "USD"

            };

           

            string requestUri = "http://<server>:<port>/sap/opu/odata/sap/SALESORDER03/SOHeaders('0000000848')/?$expand=SOItems";

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(requestUri);

           

            HttpWebResponse resp;          

            req.Credentials = new NetworkCredential(<user>, <pass>);

            req.Method = "GET";

            req.Headers.Add("X-CSRF-Token", "Fetch");

            cookieJar = new CookieContainer();

            req.CookieContainer = cookieJar;

            resp = (HttpWebResponse)req.GetResponse();

          

            csrfToken = resp.Headers.Get("X-CSRF-Token");

            setCookie = resp.Headers.Get("Set-Cookie");

           

            service.Credentials = new NetworkCredential(<user>, <pass>);

            service.AddToSOItems(so_item);

            service.AddToSOHeaders(so_header);

            service.SendingRequest += new EventHandler<System.Data.Services.Client.SendingRequestEventArgs>(service_SendingRequest);

            try

            {

                service.SaveChanges();           

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.ToString());

                Console.ReadLine();

            }

            if (resp != null)

            {

                resp.Close();

                resp = null;

            }

            if (req != null)

            {

                req.Abort();

                req = null;

            }

        }

        static void service_SendingRequest(object sender, System.Data.Services.Client.SendingRequestEventArgs e)

        {

            e.RequestHeaders.Add("x-csrf-token", csrfToken);

            e.Request.ContentType = "application/atom+xml";

            string reqUri = "http://<server>:<port>/sap/opu/odata/sap/SALESORDER03/SOHeaders";

            CookieCollection cookies = cookieJar.GetCookies(new Uri(reqUri, UriKind.Absolute));

            foreach (Cookie cookie in cookies)

            {

                e.RequestHeaders.Add("Cookie", cookie.ToString());

            }

        }

    }

But it doesn't work of course. This is not correct, I know. But can you help me in figuring out what might be the correct solution for this? This is just a trial using hard-coded data.

I'll post the exception below:


System.Data.Services.Client.DataServiceRequestException: An error occurred while

processing this request. ---> System.Data.Services.Client.DataServiceClientExce

ption: <?xml version="1.0" encoding="utf-8"?><error xmlns="http://schemas.micros

oft.com/ado/2007/08/dataservices/metadata"><code>SY/530</code><message xml:lang=

"en">Method 'CREATE_ENTITY' not implemented in data provider class.</message><in

nererror><transactionid>2D0ECCE359BAF1EB905900155DF18A00</transactionid><errorde

tails><errordetail><code>/IWBEP/CX_MGW_TECH_EXCEPTION</code><message>Method 'CRE

ATE_ENTITY' not implemented in data provider class.</message><propertyref/><seve

rity>error</severity></errordetail></errordetails></innererror></error>

   at System.Data.Services.Client.DataServiceContext.SaveResult.<HandleBatchResp

onse>d__1e.MoveNext()

   --- End of inner exception stack trace ---

   at System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchRespo

nse()

   at System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest()

   at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOpti

ons options)

   at System.Data.Services.Client.DataServiceContext.SaveChanges()

   at SalesOrderTest.Program.Main(String[] args) in C:\Users\choudsre\Documents\

Visual Studio 2010\Projects\SalesOrderTest\SalesOrderTest\Program.cs:line 116

Please help me with this?

Answers (0)