In this technical article, we will explore how to connect a client to the Rendition Server web service using C#. Rendition Server is a powerful document conversion and processing platform. By following the steps outlined below, you will be able to create a client application that interacts with the Rendition Server web service to perform document conversions.
Step 1: Setting up the Project
- Create a new Visual C# Console Application project in Visual Studio.
- Right-click on the project and select "Add" → "Service Reference."
- Enter the web service address: "http://localhost:14711/rs/conversionService/v1" (for non-SSL) or "https://localhost:14713/rs/conversionService/v1" (for SSL).
Note: Replace "localhost" with the hostname of your Rendition Server installation and adjust the port accordingly.
Step 2: Creating a Proxy Object
To access the web service, we need to create a proxy object. Use one of the endpoint configuration names that should have been added to the App.config file when adding the service reference.
Example:
var wcfClient = new ConversionInterfaceClient("NetTcpBinding_ConversionInterface");
Step 3: Creating the Input Data Object
Create an input data object that contains the file to be converted and its MIME type. You can either pass the file in memory with the conversion request or pass the file by reference to the web service. Optionally, you can add metadata to the input object.
Example:
var data = File.ReadAllBytes(@"C:\tmp\example.tif");
var input = new RenditionServerInput { Data = data, MimeType = "image/tiff" };
Step 4: Creating Conversion Parameters
Create an object that contains parameters for the conversion. Specify the strategy to be used for the conversion. Additionally, you can specify user-specific parameters to override the strategy parameters. Example:
var conversionParams = new ConversionParameters()
{
Strategy = "Raster with OCR",
CallerId = "My caller id",
TenantId = "John Doe" // Optional: Specify the tenant if tenant check is enabled
};
Step 5: Specifying User-Specific Parameters
Specify user-specific parameters to override the strategy parameters as required. These parameters can be used to customize the conversion process. Make sure the parameter names and values match the supported parameters for the chosen strategy.
Example:
var userParameters = new List<NamedValue>();
// Add user-specific parameters
userParameters.Add(new NamedValue() { Name = "ApplyOCR", Value = "True" });
userParameters.Add(new NamedValue() { Name = "OcrLanguage", Value = "eng,deu,fra" });
userParameters.Add(new NamedValue() { Name = "OcrMode", Value = "Fast" });
conversionParams.UserParameters = userParameters.ToArray();
Step 6: Authenticating (if necessary)
If your web service requires authentication, specify the username and password using the client credentials.
Example:
wcfClient.ClientCredentials.UserName.UserName = "DOMAIN\\USER";
wcfClient.ClientCredentials.UserName.Password = "SECRET";
Step 7: Initiating the Conversion and Handling the Results
Initiate the conversion process by calling the appropriate method based on whether you are converting a single document or multiple documents. Handle the resulting payload(s) as needed.
Example (Single Document Conversion):
var result = wcfClient.ConvertFile(input, conversionParams);
File.WriteAllBytes(@"C:\tmp\example.pdf", result.Payload[0].Data);
Example (Multiple Document Conversion):
int numFiles = 3;
var inputs = new RenditionServerInput[numFiles];
for (int i = 0; i < inputs.Length; ++i)
inputs[i] = input[i]; // Set up your input similar to the above example.
var result = wcfClient.ConvertFiles(inputs, conversionParams);
for (int i = 0; i < result.Payload.Length; ++i)
File.WriteAllBytes(@"C:\tmp\example" + i + ".pdf", result.Payload[i].Data);
By following the outlined steps, you can create a client application that interacts with the web service to perform document conversions. Utilizing the power of Rendition Server, you can automate and streamline your document processing workflows.