```using <http://NetSuite.com|NetSuite.com>.netsui...
# suitetalkapi
h
Copy code
using <http://NetSuite.com|NetSuite.com>.netsuite.webservices;
using System;
using <http://System.Net|System.Net>;
using System.Security.Cryptography;
using System.Xml;

namespace NetSuite {
    class SuiteTalkCourse {
        public NetSuiteService _service;
        public SuiteTalkCourse()
        {
            _service = new NetSuiteService()
            {
                CookieContainer = new CookieContainer(),
                tokenPassport = GetUpdatedTokenPassport(),

                preferences = new Preferences()
                {
                    runServerSuiteScriptAndTriggerWorkflows = false,
                    runServerSuiteScriptAndTriggerWorkflowsSpecified = true,
                }
            };
        }

        [STAThread]
        static void Main(string[] args)
        {
            <http://System.Net|System.Net>.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            SuiteTalkCourse ns = new SuiteTalkCourse();
            try
            {
                ns.getVendor();
                Console.WriteLine("");
            }
            catch (System.Web.Services.Protocols.SoapException ex) {
                string fault   = ex.Detail.FirstChild.Name;
                string code    = null;
                string message = null;
                System.Collections.IEnumerator ienum = ex.Detail.FirstChild.ChildNodes.GetEnumerator();
                while (ienum.MoveNext()) {
                    XmlNode node = (XmlNode)ienum.Current;
                    if (node.Name == "code") {
                        code = node.InnerText;
                    } else if (node.Name == "message") {
                        message = node.InnerText;
                    }
                }
                Console.WriteLine("\n***   SOAP FAULT: fault type={0} with code={1}. {2}", fault, code, message);
            }
            catch (<http://System.Net|System.Net>.WebException ex) {
                Console.WriteLine("[SOAP Fault Web Exception]: {0}", ex.Message);
            }
            catch (System.InvalidOperationException ex) {
                Console.WriteLine("[SOAP Fault Invalid Operation Exception]: {0}", ex.Message);
            }
            catch (System.Exception ex) {
                Console.WriteLine("[Error]: {0}", ex.Message);
            }
            Console.ReadLine();
        }
        static TokenPassport GetUpdatedTokenPassport()
        {
            return CreateTokenPassport(
                account: "********",
                consumerKey: "********************************************************",
                consumerSecret: "********************************************************",
                tokenId: "********************************************************",
                tokenSecret: "********************************************************"
            );
        }
        static public TokenPassport CreateTokenPassport(string account, string consumerKey, string consumerSecret, string tokenId, string tokenSecret)
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] data = new byte[20];
            rng.GetBytes(data);
            int value = Math.Abs(BitConverter.ToInt32(data, 0));
            string nonce = value.ToString();

            long timestamp = ((long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);

            string baseString = account + "&" + consumerKey + "&" + tokenId + "&" + nonce + "&" + timestamp;
            string key = consumerSecret + "&" + tokenSecret;
            string signature = "";
            var encoding = new System.Text.ASCIIEncoding();
            byte[] keyBytes = encoding.GetBytes(key);
            byte[] baseStringBytes = encoding.GetBytes(baseString);
            using (var hmacSha1 = new HMACSHA1(keyBytes))
            {
                byte[] hashBaseString = hmacSha1.ComputeHash(baseStringBytes);
                signature = Convert.ToBase64String(hashBaseString);
            }

            return new TokenPassport()
            {
                account = account,
                consumerKey = consumerKey,
                token = tokenId,
                nonce = nonce,
                timestamp = timestamp,
                signature = new TokenPassportSignature
                {
                    algorithm = "HMAC-SHA1",
                    Value = signature
                }
            };
        }
        private void getVendor() {
            RecordRef vendorRef = new RecordRef {
                internalId    = "10",
                type          = RecordType.customer,
                typeSpecified = true
            };

            _service.get(vendorRef);
        }
    }
}