Domino中使用Java访问Webservice(三)
在Lotus Designer开发工具中可以使用Java编写Webservice以及访问Webservice。这里只介绍一下如何访问Websercice。(续)
最后在Designer中创建一代理,可以使用java编写代理,也可以使用Lotusscript编写代理,下面以LotusScript编写代理,调用上面编写java类访问Websercive(用java编写代理也可以直接调用Webservice)。
Option Public
Uselsx "*javacon"
Use "WSClient"
Sub Initialize
Dim jError As JavaError
Dim serviceClient As Variant
Dim js As JAVASESSION
Dim jc As JAVACLASS
Dim session As New NotesSession
Dim db As NotesDatabase
On Error Goto catch
sURL = "http://localhost:80/DWSTest.nsf/DatabaseInfoJava"
sSOAPAction = "getUserRolesArray"
username="XXX"
xmlStr = "<soapenv:Envelope xmlns: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+"<userName xsi:type='xsd:string'>"+username+"</userName>"
xmlStr=xmlStr+"</def:"+sSOAPAction+">"
xmlStr=xmlStr+"</soapenv:Body>"
xmlStr=xmlStr+"</soapenv:Envelope>"
Set js = New JAVASESSION
Set jc = js.GetClass("WebServiceClient")
Set serviceClient = jc.CreateObject
If(serviceClient.openWSDLURL(sURL,sSOAPAction)) Then
rXMLStr = serviceClient.sendSOAPRequest(xmlStr)
Else
Msgbox "Connect fail..."
End If
Msgbox rXMLStr
Exit Sub
catch:
Set jError = js.getLastJavaError()
If jError.errormsg = "" Then
Print "Error - Err - Erl: " & Error & " - " & Err & " - " & Erl
Error 8005, Error
Else
Print "Error - Err - Erl: " & Error & " - " & Err & " - " & Erl
jsError = jError.stackTrace
Print jsError
Error 8005,jError.errormsg
js.ClearJavaError
End If
End Sub
运行上面的代理,即可查看调用Webservice后返回的数据。注,提供准确的Webservice的URL。
调试过程中可以通过SoapUI(最新版SoapUI3.6)测试Webservice接口,查看其调用Webserivce时发送的Soap请求(包括header、body等信息)。