Пример #1
0
        static void NewCaseViaWebRef()
        {
            webRef.SforceService sfBinding = null;
            webRef.LoginResult   lr        = null;
            sfBinding = new webRef.SforceService();

            //Time how long it takes
            Stopwatch sp = new Stopwatch();

            sp.Start();

            //login to Salesforce
            try
            {
                lr = sfBinding.login(username, password);
            }
            catch (Exception exc)
            {
                sfBinding = null;
                Console.WriteLine("The following error message was received while trying to connect: " + exc.Message);

                return;
            }
            //Establish the session
            sfBinding.Url = lr.serverUrl;
            sfBinding.SessionHeaderValue           = new webRef.SessionHeader();
            sfBinding.SessionHeaderValue.sessionId = lr.sessionId;

            //Create a new case
            webRef.Case sfCase = new webRef.Case();
            sfCase.Subject     = subject;
            sfCase.Description = description;
            sfCase.AccountId   = accountId;
            sfCase.Priority    = priority;
            sfCase.Status      = status;
            try
            {
                webRef.SaveResult[] res = sfBinding.create(new webRef.sObject[] { sfCase });
                //Get the results
                if (res[0].success)
                {
                    Console.WriteLine("The following case was saved sucessfully: "
                                      + res[0].id.ToString());
                }
                else
                {
                    Console.WriteLine("The following error was received: "
                                      + res[0].errors[0].message);
                    return;
                }
            }
            catch (Exception exc)
            {
                sfBinding = null;
                Console.WriteLine("The following error message was received while trying to create a case: "
                                  + exc.Message);
                return;
            }


            //Stop timer and get elapsed time
            sp.Stop();
            TimeSpan ts = sp.Elapsed;

            //Display the Results of timer
            Console.WriteLine("WebRef Runtime: "
                              + String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                              ts.Hours, ts.Minutes,
                                              ts.Seconds, ts.Milliseconds / 10));
        }
Пример #2
0
        static void NewCaseViaWebRef()
        {
            webRef.SforceService sfBinding = null;
            webRef.LoginResult lr = null;
            sfBinding = new webRef.SforceService();

            //Time how long it takes 
            Stopwatch sp = new Stopwatch();
            sp.Start();

            //login to Salesforce
            try
            {
                lr = sfBinding.login(username, password);
            }
            catch (Exception exc)
            {
                sfBinding = null;
                Console.WriteLine("The following error message was received while trying to connect: " + exc.Message);
                    
                return;
            }
            //Establish the session
            sfBinding.Url = lr.serverUrl;
            sfBinding.SessionHeaderValue = new webRef.SessionHeader();
            sfBinding.SessionHeaderValue.sessionId = lr.sessionId;

            //Create a new case
            webRef.Case sfCase = new webRef.Case();
            sfCase.Subject = subject;
            sfCase.Description = description;
            sfCase.AccountId = accountId;
            sfCase.Priority = priority;
            sfCase.Status = status;
            try
            {
                webRef.SaveResult[] res = sfBinding.create(new webRef.sObject[] { sfCase });
                //Get the results
                if (res[0].success)
                {
                    Console.WriteLine("The following case was saved sucessfully: "
                        + res[0].id.ToString());
                }
                else
                {
                    Console.WriteLine("The following error was received: "
                        + res[0].errors[0].message);
                    return;
                }
            }
            catch (Exception exc)
            {
                sfBinding = null;
                Console.WriteLine("The following error message was received while trying to create a case: "
                    + exc.Message);
                return;
            }


            //Stop timer and get elapsed time
            sp.Stop();
            TimeSpan ts = sp.Elapsed;

            //Display the Results of timer
            Console.WriteLine("WebRef Runtime: "
                + String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                    ts.Hours, ts.Minutes,
                    ts.Seconds, ts.Milliseconds / 10));

        }