본문 바로가기
Exchange & Outlook/Development

EWS를 이용한 일정 데이터 조회 구현

by 강철 벼룩 2011. 3. 6.

이 샘플은 Exchange Server 2010의 EWS를 이용해 개인의 일정을 접근해 특정 기간의 일정 건수를 가져오는 부분을 설명한다.

 

1. 네임스페이스 Microsoft.Exchange.WebServices.Data 참조 설정. 

à 해당 참조 라이브러리는 Exchange Ews Managed Api 1.0 을 다운로드 후 개발 환경에 설치.
 Exchange Ews Managed Api 1.0 다운로드 경로

2. 현재 Excahgne 웹서버의 exchange web serivce 경로로 다음과 같은 SSL 경로 (예를 들면, "https://email.contoso.com/ews/Exchange.asmx”)를 사용한다. 

 

es.Url = new Uri(https://email.contoso.com/ews/Exchange.asmx);

 

3. 기본적으로 IIS 의 인증에 종속되어 있으므로 위 Exchange 웹 서비스 IIS기본 인증상태다.

Userid는 사용자의 아이디 , pUserPWD는 패스워드 , pDomain 는 도메인 정보를 넘긴다.

es.Credentials = new NetworkCredential(pUserID, pUserPWD, pDomain);

 

4. 전체 코드

using Microsoft.Exchange.WebServices.Data;

using System.Net;

.

 

namespace UC.WebApp.Mail.xEmail

{

    public partial class Get_ScheduleCount : xMailBase

    {

        public string schedule_Count = "0";   

 

        protected void Page_Load(object sender, EventArgs e)

{      

        ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2010);

        es.Credentials = new NetworkCredential(pUserID, pUserPWD, pDomain);

        es.Url = new Uri(https://email.contoso.com/ews/Exchange.asmx);

 

CalendarFolder myCalendar = CalendarFolder.Bind(es,WellKnownFolderName.Calendar);

               

FindItemsResults<Appointment> myAppointments = myCalendar.FindAppointments(new CalendarView(DateTime.Today , (DateTime.Today.AddDays(1))));

                schedule_Count = myAppointments.Items.Count.ToString();

}

    }

}

※ Exchange Webservice와 SOAP

Exchange 웹서비스는 다른 웹서비스와 마찬가지로 SOAP 기반이므로, SOAP 사용시 XML이 전송된다. 다음은 일정의 저장을 처리하는 Save 메서드를 호출할 때 전송되는 XML 형식의 샘플이다.

관련 MSDN 사이트

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" 

               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"

               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

   <soap:Header>

      <t:RequestServerVersion Version="Exchange2010" />

   </soap:Header>

   <soap:Body>

      <m:CreateItem SendMeetingInvitations="SendToNone">

         <m:Items>

            <t:CalendarItem>

               <t:Subject>Dentist Appointment</t:Subject>

               <t:Body BodyType="Text">The appointment is with Dr. Smith.</t:Body>

               <t:Start>2009-03-02T17:00:00Z</t:Start>

               <t:End>2009-03-02T19:00:00Z</t:End>

            </t:CalendarItem>

         </m:Items>

      </m:CreateItem>