用.NET完成Lotus与异质系统的数据交互

用 .NET 完成 Lotus 与异质系统的数据交互

我们用的开发平台:

服务器: windows2000 + web 服务器: IIS5.0 + Lotus Notes/Domino 5.0.3 版;

XML Web Service 服务开发工具: Visual Studio.NET Beta2 ;

客户端: ASP web 页面或者 VB windows application 。

** 开发步骤: ** ** **


** 1) Lotus Notes/Domino ** ** 的 Notes ** ** 数据库 **

新建一个 Notes 数据库或者利用原有的数据库。在这个数据库里面至少有一个表单,在表单里有一些域,用来存放一些条目的信息。再建立几个视图,视图主要是用来按照一定规则显示文档的。比如按照时间的顺序或按照文档的点击率。

** 2) ** ** 建立 XML web service ** ** 服务 **

打开 Visual studio .NET Beta2 版,新建项目- >Visual c# 的 ASP.NET web 服务,删掉默认的 ASMX 文件,新建一个 Web 服务页面 NewsPublish.asmx ,打开 NewsPublish.asmx.cs 文件,这里将是我们编写源代码的地方。右键点击解决方案,添加引用,选择 COM 组件中的 Lotus Domino Object 组件,确定后就引用了 COM 组件,在我们的程序里面就可以访问 Notes 数据库了。好了,就可以开始编写代码提供方法调用服务了。在这里,笔者给出其中一个方法, GetNewByPostTime 提供获取指定数目的新闻条目的服务,每个新闻条目只是有提交时间、作者、标题、分类、文档标识号码等基本的信息,没有具体的内容。以下是为部分源代码。

GetNewsByPostTime 方法:

// 返回新闻条目,存储在一个数组里面

//PageSize 参数为新闻条目的数目

public NewsItem[] GetNewsByPostTime(int PageSize)

{

Domino.IViewNavigator vn;

Domino.IViewEntry h;

Domino.IDocument doc;

int index=0;

NewsItem[] Result=new NewsItem [PageSize];

//连接Notes数据库

vn=ConnectToNotesDb("","bbs.nsf","bufy_2001","All Documents",out h);

//获取每个新闻文档的信息

do

{

doc = h.Document;

Result[index]=new NewsItem ();

Result[index].Subject =doc.GetFirstItem ("Subject").Text;

Result[index].Category =doc.GetFirstItem ("categories").Text ;

Result[index].PostTime =doc.Created.ToString ();

Result[index].Author =doc.GetFirstItem("From").Text ;

Result[index].NewsID =doc.NoteID .ToString ();

index++;

h = vn.GetNextDocument(h);

}

while(h!=null&&index<PageSize);

return Result;

}

连接 Louts数据库的方法:

//这个方法建立Notes的数据库连接并获取视图的句柄

public Domino.IViewNavigator ConnectToNotesDb(string pServer,string pDbFileName,string pPassword,string pNotesView,out Domino.IViewEntry h)

{

NotesSession s=new NotesSession ();

Domino.IDatabase db;

Domino.IView v;

Domino.IViewNavigator vn;

s.Initialize (pPassword);

db=s.GetDatabase (pServer,pDbFileName,false);

v=db.GetView (pNotesView);

vn=v.CreateViewNav(0);

:h=vn.GetFirstDocument ();

return vn;

}

至此完成了 web service服务的定义,在想发布的web service服务上标上[WebMethod],这样服务就可以被客户端访问了。

** 3) 客户端的构建 **

客户端可以有很多种方法可以构建,在这里只讲述用 ASP web 站点的连接方式。客户端想获取 XML web service 服务,除了要支持 http 的连接外,还要能够解析 XML 文档。 ASP 通过调用 XMLHTTP 组件接受 XML 消息,在应 DOM 来解析 XML 文档获取我们需要的信息。

在这里,笔者只列出 ASP 请求、接受 XML 服务和解析 XML 文档的源代码:

Dim oXMLHTTP

Dim oDOM

Set oXMLHTTP=Server.CreateObject ("Microsoft.XMLHTTP")

Set oDOM = Server.CreateObject("Microsoft.XMLDOM")

' 利用 post 方法完成 xml web service 服务的请求

oXMLHTTP.open_ "POST","http://192.168.3.11/DominoXmlWebService/NewsPublish.asmx/GetNewsDetails",f_alse

' 利用 Get 方法完成 xml web service 服务的请求

'oXMLHTTP.open_ "GET","http://192.168.3.11/DominoXmlWebService/NewsPublish.asmx/GetNewsByCount?_

NewsID="&newsID&"",false

' 设置 post 方法参数

oXMLHTTP.SetRequestHeader_ "Content-Type","application/x-www-form-urlencoded"

' 发送 post 数据

oXMLHTTP.send "NewsID="&newsID&""

' 如果用 get 方法,则发送方法如下

'oXMLHTTP.send

Set oDOM=oXMLHTTP.responseXML

Set theNode=oDOM.documentElement.childNodes(0)

NewsID=theNode.ChildNodes(0).text

Subject=theNode.ChildNodes(1).text

Category=theNode.ChildNodes(2).text

Count=theNode.ChildNodes(3).text

PostTime=theNode.ChildNodes(4).text

Author=theNode.ChildNodes(5).text

Body=theNode.ChildNodes(6).text

至此,我们完成了所有的任务。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus