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;
}
}
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 serviceproperty from the new object reference.
All-Star
35218 Points
9955 Posts
Moderator
Calling method from class to use in other class
Nov 28, 2017 06:59 PM|bbcompent1|LINK
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:
This is the public class I'm trying to call out to
So how do I do this?
All-Star
53641 Points
23995 Posts
Re: Calling method from class to use in other class
Nov 28, 2017 07:17 PM|mgebhard|LINK
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.
All-Star
35218 Points
9955 Posts
Moderator
Re: Calling method from class to use in other class
Nov 28, 2017 07:24 PM|bbcompent1|LINK
Thanks man.