コード例 #1
0
        static void NewCaseViaSvcRef()
        {
            EndpointAddress epAddr = null;

            svcRef.LoginResult   lr     = null;
            svcRef.SessionHeader header = null;

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

            sp.Start();

            using (svcRef.SoapClient client = new svcRef.SoapClient("Soap"))
            {
                try
                {
                    lr = client.login(
                        null,            //LoginScopeHeader
                        username,        //username
                        password);       //password - Token is included if authenticating from outside Trusted IP Range

                    //save URL in the epaddress and the session id in the header
                    epAddr           = new EndpointAddress(lr.serverUrl);
                    header           = new svcRef.SessionHeader();
                    header.sessionId = lr.sessionId;
                }
                catch (Exception exc)
                {
                    Console.WriteLine("The following error message was received while trying to connect: " + exc.Message);
                }
            }



            using (svcRef.SoapClient queryClient = new svcRef.SoapClient("Soap", epAddr))
            {
                //Create a new case
                svcRef.Case sfCase = new svcRef.Case();
                sfCase.Subject     = subject;
                sfCase.Description = description;
                sfCase.AccountId   = accountId;
                sfCase.Priority    = priority;
                sfCase.Status      = status;

                try
                {
                    svcRef.SaveResult[] results;
                    svcRef.LimitInfo[]  info;
                    queryClient.create(
                        header,
                        null,         //assignmentruleheader
                        null,         //mruheader
                        null,         //allowfieldtruncationheader
                        null,         //disablefieldtrackingheader
                        null,         //streamingenabledheader
                        null,         //allornoneheader
                        null,         //debuggingheader
                        null,         //packageversionheader
                        null,         //emailheader
                        new svcRef.sObject[] { sfCase },
                        out info,
                        out results
                        );

                    if (results[0].success)
                    {
                        Console.WriteLine("The following case was saved sucessfully: "
                                          + results[0].id.ToString());
                    }
                    else
                    {
                        Console.WriteLine("The following error was received: "
                                          + results[0].errors[0].message);
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine("The following error message was received while trying to create a case: " + exc.Message);
                }
            }


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

            //Display the Results of timer
            Console.WriteLine("SvcRef Runtime: "
                              + String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                              ts.Hours, ts.Minutes,
                                              ts.Seconds, ts.Milliseconds / 10));
        }
コード例 #2
0
         static void NewCaseViaSvcRef()
         {
             EndpointAddress epAddr = null;
             svcRef.LoginResult lr = null;
             svcRef.SessionHeader header = null;

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

             using (svcRef.SoapClient client = new svcRef.SoapClient("Soap"))
             {
                 try
                 {

                     lr = client.login(
                         null,                  //LoginScopeHeader
                         username,              //username      
                         password);      //password - Token is included if authenticating from outside Trusted IP Range

                     //save URL in the epaddress and the session id in the header
                     epAddr = new EndpointAddress(lr.serverUrl);
                     header = new svcRef.SessionHeader();
                     header.sessionId = lr.sessionId;

                 }
                 catch (Exception exc)
                 {
                     Console.WriteLine("The following error message was received while trying to connect: " + exc.Message);
                 }
             }

             

             using (svcRef.SoapClient queryClient = new svcRef.SoapClient("Soap", epAddr))
             {
                 //Create a new case
                 svcRef.Case sfCase = new svcRef.Case();
                 sfCase.Subject = subject;
                 sfCase.Description = description;
                 sfCase.AccountId = accountId;
                 sfCase.Priority = priority;
                 sfCase.Status = status;

                 try
                 {

                     svcRef.SaveResult[] results;
                     svcRef.LimitInfo[] info;
                     queryClient.create(
                             header,
                             null,    //assignmentruleheader
                             null,    //mruheader
                             null,    //allowfieldtruncationheader
                             null,    //disablefieldtrackingheader
                             null,    //streamingenabledheader
                             null,    //allornoneheader
                             null,    //debuggingheader
                             null,    //packageversionheader
                             null,    //emailheader
                             new svcRef.sObject[] { sfCase },
                             out info,
                             out results
                          );

                     if (results[0].success)
                     {
                         Console.WriteLine("The following case was saved sucessfully: "
                         + results[0].id.ToString());
                     }
                     else
                     {
                         Console.WriteLine("The following error was received: "
                         + results[0].errors[0].message);
                     }

                 }
                 catch (Exception exc)
                 {
                     Console.WriteLine("The following error message was received while trying to create a case: " + exc.Message);
                 }
             }
             

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

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

         }