Please also have a look in our OnlineHelp for further information.

ERPConnect Services Runtime offers a very good REST interface which is well explained in the help portal (see here). The initial idea behind this interface is to offer SAP connectivity through EPPConnect Services to non-.NET environments like Java Script, PHP or Objective C. However it might be necessary as well to use the REST interfaces through C#.NET. This little sample shows the basic concept behind it. To get this sample to work, please make sure, that Basic Authentication is turned on at the SharePoint site on which ECS is running.

The first step is to create a proper WebRequest object, that points to the Webservice URL (in this sample we use the ExecuteTableQuery entry point, but the others work in the same manner). MethodType must be Post, Content Type is test/json, because we submit a JSON request in the body.

After the request is submitted the response stream is read to the end and sent to the JSON deserializer (download and reference the dll from codeplex: After deserializing it’s quite simple to access the SAP table through the row’s index and column’s name as shown in the last lines of the sample.

static void Main(string[] args)
    string url = "";
    WebRequest request = WebRequest.Create(url);
    request.Credentials = new NetworkCredential("MyAccount", "MyPassword");
    request.Method = "POST";
    request.ContentType = "text/json";
    byte[] byteArray = Encoding.UTF8.GetBytes ("{ tableName: 'T001W', settings: { RowCount: 10 } }");
    Stream myRequestStream = request.GetRequestStream();
    myRequestStream.Write(byteArray, 0, byteArray.Length);
    WebResponse ws = request.GetResponse();
    StreamReader reader = new StreamReader(ws.GetResponseStream(), Encoding.UTF8);
    String responseString = reader.ReadToEnd();
    dynamic jsonResponse = JsonConvert.DeserializeObject(responseString);
    for (int i = 0; i < jsonResponse.result.rows.Count; i++)
        Console.WriteLine(jsonResponse.result.rows[i]["WERKS"] + " " + jsonResponse.result.rows[i]["NAME1"]);