--- myst: substitutions: method: |- ```{image} /img/code_reference/net_library/connectionsettings/method.ico ``` operator: |- ```{image} /img/code_reference/net_library/connectionsettings/operator.ico ``` --- # SapConnect Class Class which provides a default implementation for connecting to SAP services and handling [CSRF protection](). **Namespace:** powerGate.Erp.Client\ **Assembly:** powerGate.Erp.Client.dll ## Inheritance Hierarchy [System.Object]()\  **powerGate.Erp.Client.SapConnect** ## Syntax ```{code-block} CSharp :linenos: public class SapConnect ``` The SapConnect type exposes the following members. ## Constructors | Type | Description | |--------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| | {{method}} SapConnect(long reconnectInterval = 1500 \* 1000) | Initializes a new instance of the SapConnect class.
The default reconnectInterval parameter, expressed in milliseconds, is set to 25 minutes. | ### Operator | Type | Description | |----------------------------------------------------------------------|--------------------------------------------------------------------------------------| | {{operator}} Implicit(SapConnect to Action\<[ErpClientSettings][]\>) | Converts the SapConnect object to an action of type Action\<[ErpClientSettings][]\>. | [ErpClientSettings]: /code_reference/net_library/erpclientsettings ## Remarks Since most of the SAP systems require **PUT requests** as the preferred method to [update]() entities in SAP, this class adapts the according [PreferredUpdateMethod]() to [UpdateMethod.PUT](). Additionally many SAP systems require by default [CSRF protection]().\ The Netweaver Gateway extension requires for every update/write operation the **X-CSRF-Token** header to be set and a **cookie**.\ Because the X-CSRF-Token expires after a certain amount of time, the Token will be automatically refreshed, on the next request after the expiration!\ Depending on the SAP Release or the security session management configuration, the Token is valid for 24 hours or 30 minutes by default.\ The default behaviour to retrieve a new token every 25min can be changed the reconnectInterval parameter in the constructor. ## Examples **Connect to a SAP service using SapConnect** ```{code-block} csharp :emphasize-lines: 7 :linenos: using (var erpclient = new ErpClient()) { var connectionSettings = new ConnectionSettings { Service = new Uri("http://sap.coolorange.com/CATALOGSERVICE"), Credentials = new System.Net.NetworkCredential("Administrator", ""), OnConnect = new SapConnect() //SAP Connection }; using (var service = erpclient.ConnectErp(connectionSettings)) Console.Write("Connected to SAP service: {0}", service.Name); } ``` **Connecting multiple SAP systems with different CSRF-Token expiration intervals:** ```{code-block} :emphasize-lines: 6, 11 :linenos: using (var erpclient = new ErpClient()) { var connectionSettings1 = new ConnectionSettings { Service = new Uri("http://sap.coolorange.com/CATALOGSERVICE"), OnConnect = new SapConnect() }; var connectionSettings2 = new ConnectionSettings { Service = new Uri("http://sap.some_other_company.com/CATALOGSERVICE"), OnConnect = new SapConnect(86400 * 1000) //tokens expire every 24h on this system }; using (var service1 = erpclient.ConnectErp(connectionSettings1)) using (var service2 = erpclient.ConnectErp(connectionSettings2)) { Console.Write("Connected to SAP-1: {0}", service1.Name); Console.Write("Connected to SAP-2: {0}", service2.Name); } } ``` ## See also **Reference** - [$sapConnect]() - [powerGate.Erp.Client namespace]()