javascript调用Exchange webservice的例子

发表时间:2008-2-28 10:24:00

详见

user66/musictom/upload/228939146.rar

===============================================================

var _xmlHttp;

var _url = 'http://mail.pudong.sh/ews/exchange.asmx';

var _domain = 'pudong.sh';

function FindFolder() {

var data = '<?xml version="1.0" encoding="utf-8"?>' +

'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +

' xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types">' +

'<soap:Body>' +

'<FindFolder Traversal="http://www.blog.com.cn/Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +

'<FolderShape>' +

'<t:BaseShape>Default</t:BaseShape>' +

'</FolderShape>' +

'<ParentFolderIds>' +

'<t:DistinguishedFolderId />' +

'</ParentFolderIds>' +

'</FindFolder>' +

'</soap:Body>' +

'</soap:Envelope>';

data = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types"><soap:Body><FindItem xmlns="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types" Traversal="http://www.blog.com.cn/Shallow"><ItemShape><t:BaseShape>IdOnly</t:BaseShape></ItemShape><ParentFolderIds><t:DistinguishedFolderId /></ParentFolderIds></FindItem></soap:Body></soap:Envelope>';

//GetItem

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

'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +

' xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types">' +

'<soap:Body>' +

'<GetItem xmlns="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/messages">' +

'<ItemShape>' +

'<t:BaseShape>IdOnly</t:BaseShape>' +

'<t:BodyType>Text</t:BodyType>' +

'<t:AdditionalProperties>' +

'<t:FieldURI FieldURI="item:Subject"/>' +

'<t:FieldURI FieldURI="item:ItemClass"/>' +

'<t:FieldURI FieldURI="item:Body"/>' +

'<t:FieldURI FieldURI="message:IsRead"/>' +

'<t:FieldURI FieldURI="message:From"/>' +

'<t:FieldURI FieldURI="message:Sender"/>' +

'<t:FieldURI FieldURI="message:ToRecipients"/>' +

'<t:FieldURI FieldURI="message:CcRecipients"/>' +

'<t:FieldURI FieldURI="message:BccRecipients"/>' +

'<t:FieldURI FieldURI="item:DisplayTo"/>' +

'<t:FieldURI FieldURI="item:DisplayCc"/>' +

'<t:FieldURI FieldURI="item:Sensitivity"/>' +

'<t:FieldURI FieldURI="item:HasAttachments"/>' +

'</t:AdditionalProperties>' +

'</ItemShape>' +

'<ItemIds>' +

'<t:ItemId ChangeKey="CQAAABYAAABecYbEuxO7T73spYRoEYJ4AAAAsFR3"/>' +

'</ItemIds>' +

'</GetItem>' +

'</soap:Body>' +

'</soap:Envelope>';

_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

_xmlHttp.open("POST", _url, false, _domain + """testuser1", "App1234");

_xmlHttp.onreadystatechange = fnCompleted;

_xmlHttp.setRequestHeader("Content-Type","text/xml");

_xmlHttp.setRequestHeader("SOAPAction","http://schemas.microsoft.com/exchange/services/2006/messages/GetItem");

_xmlHttp.send(data);

}

function fnCompleted() {

if (_xmlHttp.readyState == "4") {

if (_xmlHttp.status == "200") {

var content = _xmlHttp.responseText;

//alert(content);

document.getElementById('txtx').innerText = content;

} else {

alert('status:' + _xmlHttp.status + ';responseText:' + _xmlHttp.responseText);

}

}

}

function FindCalendar() {

var data = '<?xml version="1.0" encoding="utf-8"?>' +

'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +

' xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types">' +

'<soap:Body>' +

'<FindItem xmlns="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/messages">' +

'<ItemShape>' +

'<t:BaseShape>IdOnly</t:BaseShape>' +

'<t:BodyType>Text</t:BodyType>' +

'<t:AdditionalProperties>' +

'<t:FieldURI FieldURI="item:Subject"/>' +

'<t:FieldURI FieldURI="item:ItemClass"/>' +

'<t:FieldURI FieldURI="item:Body"/>' +

'<t:FieldURI FieldURI="message:IsRead"/>' +

'<t:FieldURI FieldURI="message:From"/>' +

'<t:FieldURI FieldURI="message:Sender"/>' +

'<t:FieldURI FieldURI="message:ToRecipients"/>' +

'<t:FieldURI FieldURI="message:CcRecipients"/>' +

'<t:FieldURI FieldURI="message:BccRecipients"/>' +

'<t:FieldURI FieldURI="item:DisplayTo"/>' +

'<t:FieldURI FieldURI="item:DisplayCc"/>' +

'<t:FieldURI FieldURI="item:Sensitivity"/>' +

'<t:FieldURI FieldURI="item:HasAttachments"/>' +

'</t:AdditionalProperties>' +

'</ItemShape>' +

'<ItemIds>' +

'<t:ItemId ChangeKey="CQAAABYAAABecYbEuxO7T73spYRoEYJ4AAAAsFR3"/>' +

'</ItemIds>' +

'</FindItem>' +

'</soap:Body>' +

'</soap:Envelope>';

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

'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +

'xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types">' +

'<soap:Body>' +

'<FindItem xmlns="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/messages" ' +

'xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types" ' +

'Traversal="http://www.blog.com.cn/Shallow">' +

'<ItemShape>' +

'<t:BaseShape>IdOnly</t:BaseShape>' +

'<t:BodyType>Text</t:BodyType>' +

'<t:AdditionalProperties>' +

'<t:FieldURI FieldURI="item:ItemClass"/>' +

'<t:FieldURI FieldURI="item:Subject"/>' +

'<t:FieldURI FieldURI="item:Categories"/>' +

'<t:FieldURI FieldURI="calendar:Start"/>' +

'<t:FieldURI FieldURI="calendar:End"/>' +

//'<t:FieldURI FieldURI="calendar:Location"/>' +

//'<t:FieldURI FieldURI="calendar:NetShowUrl"/>' +

//'<t:FieldURI FieldURI="calendar:OriginalStart"/>' +

'<t:FieldURI FieldURI="calendar:IsAllDayEvent"/>' +

'<t:FieldURI FieldURI="calendar:LegacyFreeBusyStatus"/>' +

'<t:FieldURI FieldURI="calendar:Location"/>' +

'<t:FieldURI FieldURI="calendar:When"/>' +

'<t:FieldURI FieldURI="calendar:IsMeeting"/>' +

//'<t:FieldURI FieldURI="calendar:IsCancelled"/>' +

'<t:FieldURI FieldURI="calendar:IsRecurring"/>' +

'<t:FieldURI FieldURI="calendar:MeetingRequestWasSent"/>' +

'<t:FieldURI FieldURI="calendar:IsResponseRequested"/>' +

'<t:FieldURI FieldURI="calendar:CalendarItemType"/>' +

'<t:FieldURI FieldURI="calendar:MyResponseType"/>' +

'<t:FieldURI FieldURI="calendar:Organizer"/>' +

//'<t:FieldURI FieldURI="calendar:RequiredAttendees"/>' +

//'<t:FieldURI FieldURI="calendar:OptionalAttendees"/>' +

//'<t:FieldURI FieldURI="calendar:Resources"/>' +

//'<t:FieldURI FieldURI="calendar:ConflictingMeetingCount"/>' +

//'<t:FieldURI FieldURI="calendar:AdjacentMeetingCount"/>' +

//'<t:FieldURI FieldURI="calendar:ConflictingMeetings"/>' +

//'<t:FieldURI FieldURI="calendar:AdjacentMeetings"/>' +

'<t:FieldURI FieldURI="calendar:Duration"/>' +

'<t:FieldURI FieldURI="calendar:TimeZone"/>' +

'<t:FieldURI FieldURI="calendar:AppointmentReplyTime"/>' +

'<t:FieldURI FieldURI="calendar:AppointmentSequenceNumber"/>' +

'<t:FieldURI FieldURI="calendar:AppointmentState"/>' +

//'<t:FieldURI FieldURI="calendar:Recurrence"/>' +

//'<t:FieldURI FieldURI="calendar:FirstOccurrence"/>' +

//'<t:FieldURI FieldURI="calendar:LastOccurrence"/>' +

//'<t:FieldURI FieldURI="calendar:ModifiedOccurrences"/>' +

//'<t:FieldURI FieldURI="calendar:DeletedOccurrences"/>' +

//'<t:FieldURI FieldURI="calendar:MeetingTimeZone"/>' +

'<t:FieldURI FieldURI="calendar:ConferenceType"/>' +

'<t:FieldURI FieldURI="calendar:AllowNewTimeProposal"/>' +

'<t:FieldURI FieldURI="calendar:IsOnlineMeeting"/>' +

'<t:FieldURI FieldURI="calendar:MeetingWorkspaceUrl"/>' +

'<t:FieldURI FieldURI="calendar:NetShowUrl"/>' +

'</t:AdditionalProperties>' +

'</ItemShape>' +

//'<Restriction>' +

//'<Or xmlns="http://schemas.microsoft.com/exchange/services/2006/types"> ' +

/*'<IsEqualTo>' +

'<FieldURI FieldURI="http://www.blog.com.cn/item:DateTimeCreated"/>' +

'<FieldURIOrConstant>' +

'<FieldURI FieldURI="item:DateTimeReceived"/>' +

'</FieldURIOrConstant>' +

'</IsEqualTo>' +*/

/*'<IsEqualTo>' +

'<FieldURI FieldURI="item:Subject"/>' +

'<FieldURIOrConstant>' +

'<Constant Value="eee"/>' +

'</FieldURIOrConstant>' +

'</IsEqualTo>' +

'</Or>' +*/

/*'<SearchExpression>' +

'<IsEqualTo>' +

'<FieldURI FieldURI="item:Subject"/>' +

'<FieldURIOrConstant>' +

'<Constant Value="eee"/>' +

'</FieldURIOrConstant>' +

'</IsEqualTo>' +

'</SearchExpression>' +

'</Restriction>' +*/

'<Restriction>' +

//' <ns5:Contains ContainmentComparison="IgnoreCase" ContainmentMode="FullString" ' +

//' xmlns:ns5="http://schemas.microsoft.com/exchange/services/2006/types">' +

//' <ns5:FieldURI FieldURI="http://www.blog.com.cn/item:Subject"/>' +

//' <ns5:Constant Value="eee" />' +

//' </ns5:Contains>' +

//' <ns:IsEqualTo xmlns:ns="http://schemas.microsoft.com/exchange/services/2006/types">' +

//' <ns:FieldURI FieldURI="http://www.blog.com.cn/calendar:Start"/>' +

//' <ns:FieldURIOrConstant>' +

//' <ns:Constant Value="2007-11-26T04:30:00Z" />' +

//' </ns:FieldURIOrConstant>' +

//' </ns:IsEqualTo>' +

//' <IsEqualTo xmlns="http://schemas.microsoft.com/exchange/services/2006/types">' +

//' <FieldURI FieldURI="http://www.blog.com.cn/calendar:Start"/>' +

//' <FieldURIOrConstant>' +

//' <Constant Value="2007-11-26T04:30:00Z" />' +

//' </FieldURIOrConstant>' +

//' </IsEqualTo>' +

//查询两个时间段的日程

'<And xmlns="http://schemas.microsoft.com/exchange/services/2006/types"> ' +

//' <ns1:IsGreaterThanOrEqualTo xmlns:ns1="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types">' +

//' <ns1:FieldURI FieldURI="http://www.blog.com.cn/calendar:Start"/>' +

//' <ns1:FieldURIOrConstant>' +

//' <ns1:Constant Value="2006-11-27T02:00:03Z" />' +

//' </ns1:FieldURIOrConstant>' +

//' </ns1:IsGreaterThanOrEqualTo>' +

' <IsGreaterThanOrEqualTo>' +

' <FieldURI FieldURI="calendar:Start"/>' +

' <FieldURIOrConstant>' +

' <Constant Value="2007-11-26T04:30:00Z" />' +

' </FieldURIOrConstant>' +

' </IsGreaterThanOrEqualTo>' +

' <IsLessThanOrEqualTo>' +

' <FieldURI FieldURI="calendar:End"/>' +

' <FieldURIOrConstant>' +

' <Constant Value="2007-11-27T03:00:00Z" />' +

' </FieldURIOrConstant>' +

' </IsLessThanOrEqualTo>' +

'</And>' +

'</Restriction>' +

'<ParentFolderIds>' +

'<t:DistinguishedFolderId />' +

'</ParentFolderIds>' +

'</FindItem>' +

'</soap:Body>' +

'</soap:Envelope>';

//document.getElementById('txtx').innerText = data;

//return;

_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

_xmlHttp.open("POST", _url, false, _domain + """testuser1", "App1234");

_xmlHttp.onreadystatechange = fnCalendarCompleted;

_xmlHttp.setRequestHeader("Content-Type","text/xml");

_xmlHttp.send(data);

}

function fnCalendarCompleted() {

if (_xmlHttp.readyState == "4") {

if (_xmlHttp.status == "200") {

var content = _xmlHttp.responseText;

alert(content);

document.getElementById('txtx').innerText = content;

} else {

alert('status:' + _xmlHttp.status + ';responseText:' + _xmlHttp.responseText);

}

}

}

//http://192.168.14.101/owa/?ae=PreFormAction&a=Open&t=IPM.Appointment

//&id=RgAAAAD9NptQYyvsSZXyKiVhwZY2BwBecYbEuxO7T73spYRoEYJ4AAAAsCdRAABecYbEuxO7T73spYRoEYJ4AAAAsEwvAAAP

//<t:ItemId

//ChangeKey="DwAAABYAAABecYbEuxO7T73spYRoEYJ4AAAAsFSm"

function GetUnReadMail() {

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

'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +

'xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types">' +

'<soap:Body>' +

//'<FindItem xmlns="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/messages" ' +

// 'xmlns:t="http://www.blog.com.cn/http://schemas.microsoft.com/exchange/services/2006/types" ' +

// 'Traversal="http://www.blog.com.cn/Shallow">' +

'<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" ' +

'Traversal="http://www.blog.com.cn/Shallow">' +

'<ItemShape>' +

'<t:BaseShape>IdOnly</t:BaseShape>' +

'<t:BodyType>Text</t:BodyType>' +

'<t:AdditionalProperties>' +

'<t:FieldURI FieldURI="item:ItemClass"/>' +

'<t:FieldURI FieldURI="item:Subject"/>' +

'<t:FieldURI FieldURI="item:Categories"/>' +

'<t:FieldURI FieldURI="message:IsRead"/>' +

'<t:FieldURI FieldURI="item:DateTimeReceived"/>' +

'</t:AdditionalProperties>' +

'</ItemShape>' +

/*'<Restriction>' +

' <IsEqualTo xmlns="http://schemas.microsoft.com/exchange/services/2006/types">' +

' <FieldURI FieldURI="http://www.blog.com.cn/message:IsRead"/>' +

' <FieldURIOrConstant>' +

' <Constant Value="0" />' +

' </FieldURIOrConstant>' +

' </IsEqualTo>' +

'</Restriction>' +*/

'<Restriction>' +

' <t:IsEqualTo>' +

'