locked
Calling method from class to use in other class RRS feed

  • Question

  • User-718146471 posted

    Hey all, it has been a while since I have been stuck like this. I am trying to call a public class which has my connection details from another class. The calling class looks like this:

            public static FullCalendarEvent UpdateEvent(string id, string subject, string starts, string ends)
            {
                // this is where I need to instantiate service as ExchangeService
                Appointment appointment = Appointment.Bind(service, new ItemId(id.ToString()));
    

    This is the public class I'm trying to call out to

            public ExchangeService service
            {
                get
                {
                    string login = string.Empty, pass = string.Empty, svc = string.Empty, domain = string.Empty, AutoDisc = string.Empty;
                    string sql = "SELECT ExchLogin, ExchPassWd, ExchAutoDisc, ExchSVCUrl from Settings";
                    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    conn.Open();
                    SqlDataReader rd = cmd.ExecuteReader();
                    while (rd.Read())
                    {
                        login = rd.GetValue(0).ToString();
                        pass = rd.GetValue(1).ToString();
                        AutoDisc = rd.GetValue(2).ToString();
                        svc = rd.GetValue(3).ToString();
                    }
                    conn.Close();
                    // Now that we have all the values, pass them into the service call for exchange
                    pass = Crypto.DecryptIt(pass);
                    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
                    service.Credentials = new WebCredentials(login.ToString(), pass.ToString());
                    service.AutodiscoverUrl(AutoDisc.ToString());
                    service.Url = new Uri(svc.ToString());
                    return service;
                }
            }
    

    So how do I do this?

    Tuesday, November 28, 2017 6:59 PM

Answers

  • User475983607 posted

    ExchangeService service is a property not a class.   First, new up the class that has the ExchangeService service  property.  The you can access the ExchangeService service property from the new object reference.

      

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 28, 2017 7:17 PM

All replies

  • User475983607 posted

    ExchangeService service is a property not a class.   First, new up the class that has the ExchangeService service  property.  The you can access the ExchangeService service property from the new object reference.

      

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 28, 2017 7:17 PM
  • User-718146471 posted

    Thanks man.

    Tuesday, November 28, 2017 7:24 PM