Invoking LiveCycle using Base64 encoding

You can invoke a LiveCycle service using Base64 encoding. Base64 encoding encodes attachments that are sent with a web service invocation request. That is, BLOB data is Base64 encoded, not the entire SOAP message.

"Invoking LiveCycle using Base64 encoding" discusses invoking the following LiveCycle short-lived process named MyApplication/EncryptDocument by using Base64 encoding.

注意: This process is not based on an existing LiveCycle process. To follow along with the code example, create a process named MyApplication/EncryptDocument using Workbench. (See Using Workbench.)

When this process is invoked, it performs the following actions:

  1. Obtains the unsecured PDF document that is passed to the process. This action is based on the SetValue operation. The input parameter for this process is a document process variable named inDoc.

  2. Encrypts the PDF document with a password. This action is based on the PasswordEncryptPDF operation. The password encrypted PDF document is returned in a process variable named outDoc.

Creating a .NET client assembly that uses Base64 encoding

You can create a .NET client assembly to invoke a LiveCycle service from a Microsoft Visual Studio .NET project. To create a .NET client assembly that uses base64 encoding, perform the following steps:

  1. Create a proxy class based on a LiveCycle invocation URL.

  2. Create a Microsoft Visual Studio .NET project that produces the .NET client assembly.

Creating a proxy class

You can create a proxy class that is used to create the .NET client assembly by using a tool that accompanies Microsoft Visual Studio. The name of the tool is wsdl.exe and it is located in the Microsoft Visual Studio installation folder. To create a proxy class, open the command prompt and navigate to the folder that contains the wsdl.exe file. For more information about the wsdl.exe tool, see the MSDN Help.

Enter the following command at the command prompt:

wsdl http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument?WSDL&lc_version=9.0.1

By default, this tool creates a CS file in the same folder that is based on the name of the WSDL. In this situation, it creates a CS file named EncryptDocumentService.cs. You use this CS file to create a proxy object that lets you invoke the service that was specified in the invocation URL.

Amend the URL in the proxy class to include ?blob=base64 to ensure that the BLOB object returns binary data. In the proxy class, locate the following line of code:

"http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument";

and change it to:

"http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument?blob=base64";

The Invoking LiveCycle using Base64 Encoding section uses MyApplication/EncryptDocument as an example. If you are creating a .NET client assembly for another LiveCycle service, ensure that you replace MyApplication/EncryptDocument with the name of the service.

Developing the .NET client assembly

Create a Visual Studio Class Library project that produces a .NET client assembly. The CS file that you created using wsdl.exe can be imported into this project. This project produces a DLL file (the .NET client assembly) that you can use in other Visual Studio .NET projects to invoke a service.

  1. Start Microsoft Visual Studio .NET.

  2. Create a Class Library project and name it DocumentService.

  3. Import the CS file that you created using wsdl.exe.

  4. In the Project menu, select Add Reference.

  5. In the Add Reference dialog box, select System.Web.Services.dll.

  6. Click Select and then click OK.

  7. Compile and build the project.

注意: This procedure creates a .NET client assembly named DocumentService.dll that you can use to send SOAP requests to the MyApplication/EncryptDocument service.
重要: Make sure that you added ?blob=base64 to the URL in the proxy class that is used to create the .NET client assembly. Otherwise, you cannot retrieve binary data from the BLOB object.

Referencing the .NET client assembly

Place your newly created .NET client assembly on the computer where you are developing your client application. After you place the .NET client assembly in a directory, you can reference it from a project. Also reference the System.Web.Services library from your project. If you do not reference this library, you cannot use the .NET client assembly to invoke a service.

  1. In the Project menu, select Add Reference.

  2. Click the .NET tab.

  3. Click Browse and locate the DocumentService.dll file.

  4. Click Select and then click OK.

Invoking a service using a .NET client assembly that uses Base64 encoding

You can invoke the MyApplication/EncryptDocument service (which was built in Workbench) using a .NET client assembly that uses Base64 encoding. To invoke the MyApplication/EncryptDocument service, perform the following steps:

  1. Create a Microsoft .NET client assembly that consumes the MyApplication/EncryptDocument service WSDL.

  2. Create a client Microsoft .NET project. Reference the Microsoft .NET client assembly in the client project. Also reference System.Web.Services.

  3. Using the Microsoft .NET client assembly, create a MyApplication_EncryptDocumentService object by invoking its default constructor.

  4. Set the MyApplication_EncryptDocumentService object’s Credentials property with a System.Net.NetworkCredential object. Within the System.Net.NetworkCredential constructor, specify a LiveCycle user name and the corresponding password. Set authentication values to enable your .NET client application to successfully exchange SOAP messages with LiveCycle.

  5. Create a BLOB object by using its constructor. The BLOB object is used to store a PDF document pass to the MyApplication/EncryptDocument process.

  6. Create a System.IO.FileStream object by invoking its constructor. Pass a string value that represents the file location of the PDF document and the mode in which to open the file.

  7. Create a byte array that stores the content of the System.IO.FileStream object. You can determine the size of the byte array by getting the System.IO.FileStream object’s Length property.

  8. Populate the byte array with stream data by invoking the System.IO.FileStream object’s Read method. Pass the byte array, the starting position, and the stream length to read.

  9. Populate the BLOB object by assigning its binaryData property with the contents of the byte array.

  10. Invoke the MyApplication/EncryptDocument process by invoking the MyApplication_EncryptDocumentService object’s invoke method and passing the BLOB object that contains the PDF document. This process returns an encrypted PDF document within a BLOB object.

  11. Create a System.IO.FileStream object by invoking its constructor and passing a string value that represents the file location of the password-encrypted document.

  12. Create a byte array that stores the data content of the BLOB object returned by the MyApplicationEncryptDocumentService object’s invoke method. Populate the byte array by getting the value of the BLOB object’s binaryData data member.

  13. Create a System.IO.BinaryWriter object by invoking its constructor and passing the System.IO.FileStream object.

  14. Write the byte array contents to a PDF file by invoking the System.IO.BinaryWriter object’s Write method and passing the byte array.

Quick Start: Invoking a service using base64 in a Microsoft .NET project

Invoking a service using Java proxy classes and Base64 encoding

You can invoke a LiveCycle service using Java proxy classes and Base64. To invoke the MyApplication/EncryptDocument service using Java proxy classes, perform the following steps:

  1. Create Java proxy classes using JAX-WS that consumes the MyApplication/EncryptDocument service WSDL. Use the following WSDL endpoint:

    http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument?WSDL&lc_version=9.0.1

    注意: Replace hiro-xp with the IP address of the J2EE application servier hosting LiveCycle.
  2. Package the Java proxy classes created using using JAX-WS into a JAR file.

  3. Include the Java proxy JAR file and the JAR files located in the following path:

    <Install Directory>\Adobe\Adobe LiveCycle ES4\sdk\client-libs\thirdparty

    into your Java client project’s class path.

  4. Create a MyApplicationEncryptDocumentService object by using its constructor.

  5. Create a MyApplicationEncryptDocument object by invoking the MyApplicationEncryptDocumentService object’s getEncryptDocument method.

  6. Set the connection values required to invoke LiveCycle by assigning values to the following data members:

    • Assign the WSDL endpoint and the encoding type to the javax.xml.ws.BindingProvider object’s ENDPOINT_ADDRESS_PROPERTY field. To invoke the MyApplication/EncryptDocument service using Base64 encoding, specify the following URL value:

      http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument?blob=base64

    • Assign the LiveCycle user to the javax.xml.ws.BindingProvider object’s USERNAME_PROPERTY field.

    • Assign the corresponding password value to the javax.xml.ws.BindingProvider object’s PASSWORD_PROPERTY field.

    The following code example shows this application logic:

    //Set connection values required to invoke LiveCycle  
    String url = "http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument?blob=base64"; 
    String username = "administrator"; 
    String password = "password"; 
    ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
    ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
    ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
  7. Retrieve the PDF document to send to the MyApplication/EncryptDocument process by creating a java.io.FileInputStream object by using its constructor. Pass a string value that specifies the location of the PDF document.

  8. Create a byte array and populate it with the contents of the java.io.FileInputStream object.

  9. Create a BLOB object by using its constructor.

  10. Populate the BLOB object by invoking its setBinaryData method and passing the byte array. The BLOB object’s setBinaryData is the method to call when using Base64 encoding. (See Supplying BLOB objects in service requests.)

  11. Invoke the MyApplication/EncryptDocument process by invoking the MyApplicationEncryptDocument object’s invoke method. Pass the BLOB object that contains the PDF document. The invoke method returns a BLOB object that contains the encrypted PDF document.

  12. Create a byte array that contains the encrypted PDF document by invoking the BLOB object’s getBinaryData method.

  13. Save the encrypted PDF document as a PDF file. Write the byte array to a file.