Domino中使用Java访问Webservice(三)

huangshuailei 2011-02-11

在LotusDesigner开发工具中可以使用Java编写Webservice以及访问Webservice。这里只介绍一下如何访问Websercice。(续)

最后在Designer中创建一代理,可以使用java编写代理,也可以使用Lotusscript编写代理,下面以LotusScript编写代理,调用上面编写java类访问Websercive(用java编写代理也可以直接调用Webservice)。

OptionPublic

Uselsx"*javacon"

Use"WSClient"

SubInitialize

DimjErrorAsJavaError

DimserviceClientAsVariant

DimjsAsJAVASESSION

DimjcAsJAVACLASS

DimsessionAsNewNotesSession

DimdbAsNotesDatabase

OnErrorGotocatch

sURL="http://localhost:80/DWSTest.nsf/DatabaseInfoJava"

sSOAPAction="getUserRolesArray"

username="XXX"

xmlStr="<soapenv:Envelopexmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"

xmlStr=xmlStr+"xmlns:xsd='http://www.w3.org/2001/XMLSchema'xmlns:soapenv='"

xmlStr=xmlStr+"http://schemas.xmlsoap.org/soap/envelope/'"

xmlStr=xmlStr+"xmlns:def='http://DefaultNamespace'>"

xmlStr=xmlStr+"<soapenv:Header/>"

xmlStr=xmlStr+"<soapenv:Body>"

xmlStr=xmlStr+"<def:"+sSOAPAction+"soapenv:encodingstyle="

xmlStr=xmlStr+"'http://schemas.xmlsoap.org/soap/encoding/'>"

xmlStr=xmlStr+"<userNamexsi:type='xsd:string'>"+username+"</userName>"

xmlStr=xmlStr+"</def:"+sSOAPAction+">"

xmlStr=xmlStr+"</soapenv:Body>"

xmlStr=xmlStr+"</soapenv:Envelope>"

Setjs=NewJAVASESSION

Setjc=js.GetClass("WebServiceClient")

SetserviceClient=jc.CreateObject

If(serviceClient.openWSDLURL(sURL,sSOAPAction))Then

rXMLStr=serviceClient.sendSOAPRequest(xmlStr)

Else

Msgbox"Connectfail..."

EndIf

MsgboxrXMLStr

ExitSub

catch:

SetjError=js.getLastJavaError()

IfjError.errormsg=""Then

Print"Error-Err-Erl:"&Error&"-"&Err&"-"&Erl

Error8005,Error

Else

Print"Error-Err-Erl:"&Error&"-"&Err&"-"&Erl

jsError=jError.stackTrace

PrintjsError

Error8005,jError.errormsg

js.ClearJavaError

EndIf

EndSub

运行上面的代理,即可查看调用Webservice后返回的数据。注,提供准确的Webservice的URL。

调试过程中可以通过SoapUI(最新版SoapUI3.6)测试Webservice接口,查看其调用Webserivce时发送的Soap请求(包括header、body等信息)。

相关推荐

DodderB / 0评论 2010-08-13
hyMiss / 0评论 2010-05-10