EWS
2008. 7. 30.
안혁
http://hyok.kr
-
* 시나리오
-
1. admin@hyok.kr 계정으로 EWS를 연결하여 user1@hyok.kr 계정의 일정을 요청
2. admin@hyok.kr 계정은 user1@hyok.kr 사서함에 대한 권한을 가지고 있음
3. wrongid@hyok.kr 사서함은 존재하지 않음
4. EWS 요청 시 C#에서는 다음의 방식으로 인증합니다.
> binding.Credentials = new NetworkCredential("admin", "wow!", "hyok.kr");
-
-
* 성공 요청(권한을 가지고 있는 사서함 요청)
-
1. Request
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-16"?> <FindItemType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Traversal="Shallow"> <ItemShape xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <BaseShape xmlns="http://schemas.microsoft.com/exchange/services/2006/types">Default</BaseShape> </ItemShape> <CalendarView MaxEntriesReturned="25" StartDate="2008-07-29T00:00:00+09:00" EndDate="2008-07-30T00:00:00+09:00" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" /> <ParentFolderIds xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <DistinguishedFolderId Id="calendar" xmlns="http://schemas.microsoft.com/exchange/services/2006/types"> <Mailbox> <EmailAddress>user1@hyok.kr</EmailAddress> </Mailbox> </DistinguishedFolderId> </ParentFolderIds> </FindItemType> |
-
2. Response
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="utf-16"?> <FindItemResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ResponseMessages xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <FindItemResponseMessage ResponseClass="Success"> <ResponseCode>NoError</ResponseCode> <RootFolder IncludesLastItemInRange="true" TotalItemsInView="0"> <Items xmlns="http://schemas.microsoft.com/exchange/services/2006/types" /> </RootFolder> </FindItemResponseMessage> </ResponseMessages> </FindItemResponseType> |
-
* 실패 요청(존재 하지 않는 사서함 요청)
-
1. Request
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-16"?> <FindItemType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Traversal="Shallow"> <ItemShape xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <BaseShape xmlns="http://schemas.microsoft.com/exchange/services/2006/types">Default</BaseShape> </ItemShape> <CalendarView MaxEntriesReturned="25" StartDate="2008-07-29T00:00:00+09:00" EndDate="2008-07-30T00:00:00+09:00" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" /> <ParentFolderIds xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <DistinguishedFolderId Id="calendar" xmlns="http://schemas.microsoft.com/exchange/services/2006/types"> <Mailbox> <EmailAddress>wrongid@hyok.kr</EmailAddress> </Mailbox> </DistinguishedFolderId> </ParentFolderIds> </FindItemType> |
-
2. Response
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-16"?> <FindItemResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ResponseMessages xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> <FindItemResponseMessage ResponseClass="Error"> <MessageText>SMTP 주소에연결된사서함이없습니다.</MessageText> <ResponseCode>ErrorNonExistentMailbox</ResponseCode> <DescriptiveLinkKey>0</DescriptiveLinkKey> <MessageXml> <t:Value Name="SmtpAddress" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">wrongid@hyok.kr</t:Value> </MessageXml> </FindItemResponseMessage> </ResponseMessages> </FindItemResponseType> |
-
* C#을 사용하여 테스트하는 경우
-
1. 실제 사용하려면 Url 정보와 계정 정보를 수정해야 할 것임
-
2. 윈폼 어플리케이션 생성 후 Form1.cs 디자인에서 텍스트 박스 2개 추가
-
3. From.cs 코드에서 다음을 작성
-
1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
Public Form1() { InitializeComponent(); CallEWS(); } private void CallEWS() { ExchangeServiceBinding binding = new EWSCalendarTest.EWS.ExchangeServiceBinding(); binding.Url = "http://localhost/ews/exchange.asmx"; binding.Credentials = new NetworkCredential("admin", "wow!", "hyok.kr"); FindItemType findRequest = new FindItemType(); findRequest.Traversal = ItemQueryTraversalType.Shallow; DistinguishedFolderIdType calendarType = new DistinguishedFolderIdType(); calendarType.Id = DistinguishedFolderIdNameType.calendar; calendarType.Mailbox = new EmailAddressType(); calendarType.Mailbox.EmailAddress = "user1@hyok.kr"; findRequest.ParentFolderIds = new DistinguishedFolderIdType[] { calendarType }; findRequest.Item = CreateCalendarViewForToday(); findRequest.ItemShape = new ItemResponseShapeType(); findRequest.ItemShape.BaseShape = DefaultShapeNamesType.Default; FindItemResponseType findResponse = binding.FindItem(findRequest); CreateXmlMessageTextFile(findRequest, findResponse); } private CalendarViewType CreateCalendarViewForToday() { DateTime dtToday12AM = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, DateTimeKind.Local); CalendarViewType calendarView = new CalendarViewType(); calendarView.StartDate = dtToday12AM; calendarView.EndDate = calendarView.StartDate.AddDays(1); calendarView.MaxEntriesReturned = 25; calendarView.MaxEntriesReturnedSpecified = true; return calendarView; } public void CreateXmlMessageTextFile(EWS.BaseRequestType request, EWS.BaseResponseMessageType response) { using (StringWriter myReqWriter = new StringWriter()) { XmlSerializer mySerializer = new XmlSerializer(request.GetType()); mySerializer.Serialize(myReqWriter, request); textBox1.Text = myReqWriter.ToString(); } using (StringWriter myRespWriter = new StringWriter()) { XmlSerializer mySerializer = new XmlSerializer(response.GetType()); mySerializer.Serialize(myRespWriter, response); textBox2.Text = myRespWriter.ToString(); } } |
'Exchange Server 2007,2010 > Exchange Web Services' 카테고리의 다른 글
EWS Managed API 1.0 RC (0) | 2009.09.16 |
---|