I'm a new user using c# and exchange web service and I got a problem. What I'm trying to do is to add an appointment to the calendar of outlook.
ExchangeService service = null;
public WebService1()
{
service = new ExchangeService(ExchangeVersion.Exchange2013);
service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials("user1@mydomain`enter code here`.com", "password");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
service.Url = new Uri("https://mydomain/EWS/Exchange.asmx");
service.TraceListener = new TraceListener();
// Optional flags to indicate the requests and responses to trace.
service.TraceFlags = TraceFlags.All;
service.TraceEnabled = true;
service.TraceListener.Trace("begin", service.HttpHeaders.ToString());}
[WebMethod]
public string addMeeting(string userNameList, string subject, string content, string beginDate, string endDate, string location="", string optionalUserList="", string remindTime="")
{
try
{
Appointment meeting = Appointment.Bind(service, new ItemId("meeting"));
if (userNameList == "")
{
return "FAIL: NO USER IS ADDED! PLEASE CHECK AGAIN!";
}
meeting.Subject = subject.Trim() == "" ? "未知主题" : subject;
meeting.Body = content.Trim() == "" ? "未知内容" : content;
meeting.Start = DateTime.Parse(beginDate);
meeting.End = DateTime.Parse(endDate);
meeting.Location = location == "" ? "未知地点" : location;
string[] userListArr = userNameList.Split(new Char[] { ';', ',' });
foreach (string s in userListArr)
{
if (s.Trim() != "")
{
meeting.RequiredAttendees.Add(s);
}
}
string[] opUserListArr = optionalUserList.Split(new Char[] { ';', ',' });
foreach (string s in opUserListArr)
{
if (s.Trim() != "")
{
meeting.OptionalAttendees.Add(s);
}
}
remindTime = remindTime.Trim() == "" ? "60" : remindTime;
meeting.ReminderMinutesBeforeStart = int.Parse(remindTime);
meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
return "SUCCESS";
}
catch (Exception ex)
{
return ex.Message + "\n" + ex.StackTrace + "\n\n" + ex.Source +" \n" + ex.ToString();
}
}
And this works well when I debug it in visio studio, and then I put it into IIS, NOTHING GOES RIGHT! And I found that in the log file on the exchange server, error code 401 is logged. And then I found that the ews' authentication is set to be "base, NTLM, Windows authentication, Windows SharePoint safty, OAuth".
I'm asking how can I change my code to get these authentications. Thanks!
Forgive me of my poor English.