SuiteTalk platform allows two different ways of handling sessions:
- Session Level Credentials: Client creates a Passport object and authenticates using it, receiving session information. Each subsequent SOAP request is then authenticated using these session information.
- Request Level Credentials: Client creates a Passport object but does not log in. It instead sends the Passport object with each SOAP request, so that the authentication is processed with each request.
Best practices for using SuiteTalk authentication:
- For Session Level Credentials, the client needs to maintain cookie information, because session information is stored in cookies. Any subsequent request will fail if session information is not provided.
- For Request Level Credentials, it is recommended not to maintain cookie information, as the subsequent request might then be referring to an expired and/or non-existent session. This is especially important when running multiple request at the same time with SuiteCloud Plus and often leads to the requests being rejected with "Session timed out" error.
Sample C# code for Session Level Credentials:
// Create NetSuiteService instance
NetSuiteService _service = new NetSuiteService();
// Create CookieContainer for keeping session information
_service.CookieContainer = new System.Net.CookieContainer();
// Create Passport
Passport passport = new Passport();
passport.account = "ACCT12345";
passport.email = "user@domain.com";
passport.password = "password";
// Log in
SessionResponse response_login = _service.login(passport);
if (response_login.status.isSuccess)
{
// Create an example reference to Customer ID 100
RecordRef recref = new RecordRef();
recref.type = RecordType.customer;
recref.typeSpecified = true;
recref.internalId = "100";
// Fetch Customer record
ReadResponse response_get = _service.get(recref);
// Log out
_service.logout();
}
else
{
// Authentication failed
}
Sample C# code for Request Level Credentials:
// Create NetSuiteService instance
NetSuiteService _service = new NetSuiteService();
// Do not create CookieContainer as we don't want to keep session information
// _service.CookieContainer = new System.Net.CookieContainer();
// Create Passport and assign it to _service.passport
Passport passport = new Passport();
passport.account = "ACCT12345";
passport.email = "user@domain.com";
passport.password = "password";
_service.passport = passport;
// Create an example reference to Customer ID 100
RecordRef recref = new RecordRef();
recref.type = RecordType.customer;
recref.typeSpecified = true;
recref.internalId = "100";
// Fetch Customer record
ReadResponse response_get = _service.get(recref);
No comments:
Post a Comment