Thursday, December 6, 2018

Sample C# Code maintaining the Cookie from Login

Below is a sample C# code on how to invoke a 'GET' of a customer record. So that cookies are maintained and will be reused on the next requests before logout, the CookieContainer must be set.

            //Set passport information
            Passport passport = new Passport();
   = "";
            passport.account = "143190";
            passport.password = "password";
            RecordRef role = new RecordRef();
            role.internalId = "3"; //internal id of the user role to be used
            passport.role = role;

            //instantiate NetSuite service
            NetSuiteService NSService = new NetSuiteService();

            //set cookie container to handle session information
            NSService.CookieContainer = new CookieContainer();

            Status status = NSService.login(passport).status;

            //Set BaseRef parameters
            RecordRef recRef = new RecordRef();
            recRef.internalId = "10";
            recRef.type = RecordType.customer;
            recRef.typeSpecified = true;

            //send WS request
            ReadResponse response = NSService.get((BaseRef)recRef);

            //Cast response as customer object
            Customer customer = (Customer)response.record;


No comments:

Post a Comment