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 in the Web service design element. Code Design Web Services. 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.

 

In the Web Service Properties box Basics Signature
The fields on the basic tab are described as follows: Name (required ): The Web Service name 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: Related Fields of web service information data (generally, the information of this field cannot exceed one sentence; a long description of the web service or information 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): Used The name of the class of 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 fields are described as follows: Run as Web user: This option enables Web service code can be 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. Web Service (for remote debugging information, see the "using the remote debugger" topic of the Lotus Domino designer help "). 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 1. allow most Lotus scripts and Java operations to run correctly. For reading/writing files, creating COM objects, or performing network operations, set it to 2 or 3 as needed (for more information, see the "restricted Lotus script and Java agent operations" help topic of Lotus Domino designer "). 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 enables only the database Users who access "read public documents" in the ACL can use this Web Service. This is useful when they 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 that the operation name exists in the external request Soap action header (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, the field value is 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 Edit your Java 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 $ () + "datadominohtmlworkflow" + xmlfilename If outputstream. Open (outputfile) then Call outputstream. 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. Call a web service. 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 sub Errhandle: msgbox STR (ERR) + "row number: "+ STR (ERL) +" error message saveworkflowxml: "+ error $ Resume next End sub 2, 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; // Definition WebService path; VaR ws_url: String = "http: // server/MIS/flow. nsf/saveworkflow? WSDL "; // defines the WebService object; var WS: WebService = new WebService (ws_url); // call WebService method; VaR callobject = ws. saveworkflowxml (_ parent. workflowxml, _ global. workxml. tostring (); // sets the returned result object; callobject. onresult = function (result) {trace (result ); } // If a call error is returned (this is optional); callobject. onfault = function (fault ){ Trace ("fault:" + fault. faultstring ); } 4. Calls in Java proxy WebService, 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 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 Parameters Soaphttpconnection ST = new soaphttpconnection (); // Create a call Call call = new call (); Call. setsoaptransport (ST ); Call. setsoapmappingregistry (SMR ); Call. settargetobjecturi ("http://tempuri.org/message "); 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 (soapexception e ){ System. Err. println ("caught soapexception (" + E. getfaultcode () + "):" + E. getmessage ()); Return; } // Check the return value If (RESP! = NULL &&! Resp. generatedfault ()){ Parameter ret = resp. getreturnvalue (); Object value = ret. getvalue (); System. Out. println ("answer -->" + value ); } Else { Fault 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.