Apply WebService in Lotus Domino

Source: Internet
Author: User

Lotus Domino v7.0 introduces a new Web service design element in Lotus Domino designer. Therefore, it is easier to use web services in Lotus Domino application development. Among them, Lotus Domino is responsible for processing all the WSDL creation and soap operations. All we need to do is to write code in the Web service design element to design the web service. Lotus Domino can publish the WSDL file, convert the introduced SOAP request into a method call on the class, and return the result of the method (if any) as a soap response. Lotus Domino Web services can be written in Lotus script or Java. There are many methods to call Web Services. 1. Design Web Services.

 

Click Create web service. Design your own web services.

Basics tab in the Web Service Properties box
The fields on the basic tab are described as follows: Name (required): Web Service name, which is the name used by the client to access the WSDL file or service. Alias: a name other than name. You can use this name to access the service. Comment: a field related to the information data of the Web Service (generally, the information of this field cannot exceed one sentence; a long description or information about the web service should be written in the comments of the Code ). Warn if the WSDL interface is modified: This option instructs you whether the changes made to the Code have modified the WSDL file generated by the web service. This is useful to ensure the consistency of the WSDL file, but you should be aware that if this option is selected, you will not be able to save the service with the modified WSDL file. Porttype class (required): name of the class used as the Web service interface. In other words, it is a class with a public method accessible to the user in the Web service code. The second signature in the box is the security signature (see figure 4 ). Figure 4. Security tab in the Web Service Properties box
The Security tab field is described as follows: Run as Web user: This option enables the Web Service Code to run in the security context of the user who calls the Web Service (by default, it will run in the security context of the last signature web service ID in Lotus Domino designer ). Run on behalf of: this field allows users to be specified. If you want the Web Service Code to run in the security context of a specific user, instead of the security context of the last signature web service ID in Lotus Domino designer. Allow remote debugging: This option allows remote debugging of web services (for more information about remote debugging, see the Lotus Domino designer help topic "using the remote debugger "). Profile this Web Service: This option will generate analysis information when the web service is running (for analysis information, see the "profiling agents and Web Services" help topic of Lotus Domino designer "). Set runtime security level: set to 1 to allow most Lotus script and Java operations to run correctly. For reading/writing files, creating COM objects, or performing network operations, set to 2 or 3 (for more information, see the Lotus Domino designer help topic "restricted Lotus script and Java agent operations "). Default access for this Web Service: This option allows you to control which users can access the Web Service and beyond the control that can be performed using the database ACL (if the anonymous user cannot access the Web service, when you try to connect, you will receive the error 401 Access denied or 404 Not found ). Allow public access users to use this Web Service: This option allows only users with "read public documents" access in the database ACL to use this web service, this is useful when you do not want to grant full reader access permissions (or higher levels) to a large number of users. The third tab in the box is the options tab (see figure 5 ). Figure 5. Options tab in the Web Service Properties box
The fields on the options tab are described as follows: programming model: the available options are RPC or message (RPC is used in most cases ). SOAP message format: in this field, select the SOAP message format for this web service. The default format in Lotus Domino v7.0 is rpc/encoded. Include operation name in soap Action: This option requires the operation name to exist in the soap action header of external requests (rarely required ). Port type name: by default, this field value is the same as the value of the porttype class field on the Basics tab (although you can use any desired name ). This value is used to generate a WSDL file. Service element name: by default, this field value is the porttype name plus the word Service (although you can use any desired name ). This value is used to generate a WSDL file. Service port name: by default, this field value is Domino (although you can use any desired name ). This value is used to generate a WSDL file.

You can choose to use Lotus script or Java to edit your web service. The following is a simple example of writing Lotus script. % Include "lsxsd. LSS "class saveworkflow sub new end sub function saveworkflowxml (xmlfilename as string, xmltext as string) as string on error goto errhandle dim outputstream as notesstream dim session as new notessession set outputstream = session. createstream dim outputfile as string outputfile = curdir $ () + "/data/Domino/html/workflow/" + xmlfilename if outputstream. open (outputfile) then call outputstrea M. writetext (xmltext, eol_crlf) Call outputstream. close end if saveworkflowxml = "1" Exit functionerrhandle: msgbox STR (ERR) + "row number:" + STR (ERL) + "error message saveworkflow: saveworkflowxml "+ error $ resume next end function End Class 1. Web service call. 1. WebService is called in the Lotus script proxy. On the window platform, we can use mssoap toolkit to call it. You can download mssoap toolkit3.0 and install mssoap toolkit3.0 on the server. The code in the proxy is as follows: Sub initialize on error goto errhandle dim ss as new notessession dim doc as notesdocument set Doc = ss. documentcontext dim client as variant dim xmlfilename as string dim xmltext as string xmlfilename = Doc. xmlfilename (0) xmltext = Doc. xmltext (0) Set Client = Createobject ("mssoap. soapclient30 ") Call client. mssoapinit ("http: // server/MIS/flow. NSF/saveworkflow? WSDL ") dim result as string if not client is nothing then result = client. saveworkflowxml (xmlfilename, xmltext) else result = "no web" end if exit suberrhandle: msgbox STR (ERR) + "row number:" + STR (ERL) + "error message saveworkflowxml: "+ error $ resume next end sub2, WebService is called in JavaScript. VaR xmlfilename = document. all. xmlfilename. valuevar xmltext = document. all. xmltext. value var XMLHTTP = new activexobject ("Microsoft. XMLHTTP "); var soapmessage, soapdata, URL; // set the SOAP message soapmessage =" <? XML version =/"1.0/" encoding =/"UTF-8/"?> "; Soapmessage + =" <soap: envelope xmlns: xsi =/"http://www.w3.org/2001/XMLSchema-instance/" "+" xmlns: XSD =/"http://www.w3.org/2001/XMLSchema/" xmlns: Soap =/"http://schemas.xmlsoap.org/soap/envelope//"> "; soapmessage + = "<soap: Body>"; // set the data for soap body ---- begin ------ soapdata = "<saveworkflowxml xmlns =/" http://tempuri.org/"> "; soapdata + = "<xmlfilename>" + xmlfilename + "</xmlfilename> "; Soapdata + =" <xmltext> "+ xmltext +" </xmltext> "; soapdata + =" </saveworkflowxml> "; // set the data for soap body ---- end ------ soapmessage = soapmessage + soapdata + "</soap: Body>"; soapmessage = soapmessage + "</soap: envelope> "; vaR urlstr = "http: // server/MIS/flow. NSF/saveworkflow? Openwebservice "XMLHTTP. open ("Post", urlstr, false); XMLHTTP. setRequestHeader ("Content-Type", "text/XML; charset = UTF-8"); XMLHTTP. setRequestHeader ("soapaction", "http://tempuri.org/onlineandmsg"); XMLHTTP. send (soapmessage); var x = XMLHTTP. responsexml; 3. WebService is called in flash. Import MX. Services. WebService; // defines the WebService path; var ws_url: String = "http: // server/MIS/flow. nsf/saveworkflow? WSDL "; // defines the WebService object; var WS: WebService = new WebService (ws_url); // calls the WebService method; var callobject = ws. saveworkflowxml (_ parent. workflowxml, _ global. workxml. tostring (); // sets the returned result object; callobject. onresult = function (result) {trace (result) ;}// if an error is returned (this is optional); callobject. onfault = function (fault) {trace ("fault:" + fault. faultstring);} 4. Call WebService in the Java proxy. First, introduce the relevant package in the proxy project. Import Lotus. domino. *; import Java. io. *; import Java. util. *; import java.net. *; import Org. w3C. dom. *; import Org. apache. soap. util. XML. *; import Org. apache. soap. *; import Org. apache. soap. encoding. *; import Org. apache. soap. encoding. soapenc. *; import Org. apache. soap. RPC. *; import Org. apache. soap. transport. HTTP. soaphttpconnection; public class javaagent extends agentbase {public void notesmain () {try {session Session = getsession (); agentcontext = session. getagentcontext (); document DOC = agentcontext. getdocumentcontext (); string xmlfilename = Doc. getitemvaluestring ("xmlfilename") string xmltext = Doc. getitemvaluestring ("xmltext") // (your code goes here) url = new URL ("http: // server/MIS/flow. NSF/saveworkflow? WSDL "); soapmappingregistry SMR = new soapmappingregistry (); stringdeserializer SD = new stringdeserializer (); SMR. maptypes (constants. ns_uri_soap_enc, new QNAME ("", "result"), null, null, SD); // create the transmission path and parameter soaphttpconnection ST = new soaphttpconnection (); // create a call = new call (); call. setsoaptransport (ST); call. setsoapmappingregistry (SMR); call. settargetobjecturi ("http://tempuri.org/m Essage/"); call. setmethodname ("saveworkflowxml"); call. setencodingstyleuri ("http://schemas.xmlsoap.org/soap/encoding/"); vector Params = new vector (); Params. addelement (new parameter ("xmlfilename", String. class, xmlfilename, null); Params. addelement (new parameter ("xmltext", String. class, xmltext, null); call. setparams (Params); Response resp = NULL; try {resp = call. invoke (URL, "");} catch (SOA Pexception e) {system. err. println ("caught soapexception (" + E. getfaultcode () + "):" + E. getmessage (); return;} // check the returned value if (RESP! = NULL &&! Resp. generatedfault () {parameter ret = resp. getreturnvalue (); object value = ret. getvalue (); system. out. println ("answer -->" + value);} else {fault = resp. getfault (); system. err. println ("generated fault:"); system. out. println ("fault code =" + fault. getfaultcode (); system. out. println ("fault string =" + fault. getfaultstring ();} catch (exception e) {e. printstacktrace ();}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.