c ajax定时获取,jquery定时ajax调用web service

最经一直在做moss方面的开发,客户也上了exchange,也做了moss和exchange的sso,但是有新邮件还是要点击进入邮箱才可以查看。客户说要是有新邮件的时候可以提示一下,以为我们以前做过有【每日提醒】,包括每天的日程、文档、邮件,好吧,如果有新的就让【每日提醒】这几个字闪动吧。

思路就是用ajax定时查看有无新内容,如果有的用一个定时器让文字闪动(通过变化文件的color实现),如果没有就关闭定时器,恢复文字的颜色。这里邮件的获取用到了exchange的web service http://mail.moss.com/ews/exchange.asmx ,结合jquery和一般处理程序ashx的ajax。

jquery:1.3.2

vs:2008

一般处理程序的代码如下

Handler1.ashx

using System;

using System.Collections;

using System.Data;

using System.Linq;

using System.IO;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Linq;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.Portal.SingleSignon;

using Microsoft.SharePoint.Portal.SingleSignonAdministration;

using System.Net;

using WebApplication1.mtn.gfdx.cds.ucs.mail;

using Microsoft.SharePoint.Portal;

using System.Text;

using System.Text.RegularExpressions;

namespace WebApplication1

{

/// /// $codebehindclassname$ 的摘要说明

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class Handler1 : IHttpHandler

{

private const string exchangeMailWebRefUrl = @"http://mail.moss.com/ews/exchange.asmx";

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "application/json";

bool resultjson = false ;

resultjson = GetMail();

string reStr;

if (resultjson)

reStr = string.Format("{{contains:'{0}'}}", "true");

else

reStr = string.Format("{{contains:'{0}'}}", "false");

context.Response.Write(reStr);

}

private void WriteFile(string str)

{

try

{

File.AppendAllText(@"c:\test.txt", str);

File.AppendAllText(@"c:\test.txt", Environment.NewLine);

}

catch { }

}

/// /// 获取是否包含未读Exchange邮件信息

///

///

public bool GetMail()

{

bool result = false;

//DataRow row;

try

{

ICredentials creds = new NetworkCredential("administrator", "123", "moss");

ExchangeServiceBinding exchangeServer = new ExchangeServiceBinding();

exchangeServer.Credentials = creds;

exchangeServer.Url =exchangeMailWebRefUrl

exchangeServer.Credentials = creds;

DistinguishedFolderIdType[] folderIdArray = new DistinguishedFolderIdType[1];

folderIdArray[0] = new DistinguishedFolderIdType();

folderIdArray[0].Id = DistinguishedFolderIdNameType.inbox;

PathToUnindexedFieldType ptuftDisplayName = new PathToUnindexedFieldType();

ptuftDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName;

PathToExtendedFieldType pteftComment = new PathToExtendedFieldType();

pteftComment.PropertyTag = "0x3004";

pteftComment.PropertyType = MapiPropertyTypeType.String;

GetFolderType myFolderType = new GetFolderType();

myFolderType.FolderIds = folderIdArray;

myFolderType.FolderShape = new FolderResponseShapeType();

myFolderType.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;

myFolderType.FolderShape.AdditionalProperties = new BasePathToElementType[2];

myFolderType.FolderShape.AdditionalProperties[0] = ptuftDisplayName;

myFolderType.FolderShape.AdditionalProperties[1] = pteftComment;

GetFolderResponseType myFolder = exchangeServer.GetFolder(myFolderType);

FolderInfoResponseMessageType firmtInbox = (FolderInfoResponseMessageType)myFolder.ResponseMessages.Items[0];

PathToUnindexedFieldType ptuftSubject = new PathToUnindexedFieldType();

ptuftSubject.FieldURI = UnindexedFieldURIType.itemSubject;

PathToUnindexedFieldType ptuftBody = new PathToUnindexedFieldType();

ptuftBody.FieldURI = UnindexedFieldURIType.itemAttachments;

PathToExtendedFieldType ppteftFlagStatus = new PathToExtendedFieldType();

ppteftFlagStatus.PropertyTag = "0x1090";

ppteftFlagStatus.PropertyType = MapiPropertyTypeType.Integer;

FindItemType findItemRequest = new FindItemType();

findItemRequest.Traversal = ItemQueryTraversalType.Shallow;

findItemRequest.ItemShape = new ItemResponseShapeType();

findItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.Default;

findItemRequest.ParentFolderIds = new FolderIdType[1];

findItemRequest.ParentFolderIds[0] = firmtInbox.Folders[0].FolderId;

FindItemResponseType firt = exchangeServer.FindItem(findItemRequest);

MessageType mt = new MessageType();

//int newMail = 0;

//int totalMail = 0;

foreach (FindItemResponseMessageType firmtMessage in firt.ResponseMessages.Items)

{

if (firmtMessage.RootFolder.TotalItemsInView > 0)

{

foreach (ItemType it in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)

{

mt = it as MessageType;

if (mt.IsRead == false)

{

result = true;

break;

}

}

}

}

}

#region

catch (SingleSignonException ssoex)

{

}

catch (Exception ex)

{

}

#endregion

return result;

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

前台的JavaScript代码如下

Code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值