How to Consume LEADTOOLS WCF in Java Netbeans

Take the following steps to start a project and to add some code that performs OCR on an image using Java:

  1. Start NetBeans IDE 6.1.
  2. Choose File-> New Project... from the menu.
  3. In the New Project dialog box, choose "Java" in the Categories list, and choose "Java Application" in the Projects list. And press 'Next'.
  4. Type the project name as "OCRImage" in the Project Name field, and if desired type a new location for your project or select a directory using the Browse button. Then choose 'Finish'.
  5. From the 'Projects' window, Right-Click on the Project 'OCRImage' icon and choose 'New'-> 'Web Service Client'.
  6. The 'New Web Service Client' wizard will appear. Choose 'WDSL URL' as the WDSL file location. Specify the URL as: http://localhost:8080/LeadtoolsServicesHost/OcrService.svc
  7. Set the Proxy options using the 'Proxy' button. And press 'Finish'.
  8. Open 'Notepad' and Paste the following into it:


    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  
    <bindings wsdlLocation="[PATH]\OcrService.svc.wsdl" xmlns="">  
       <bindings node="wsdl:definitions/wsdl:types/xs:schema" xmlns:xs=""  
          <globalBindings xmlns="">  
             <generateElementProperty xmlns="">false</generateElementProperty>  

    Important Note: To get the [PATH], go to the project 'OCRImage' directory => 'xml-resources' => 'web-service-references' => 'OcrService.svc'=> 'wsdl' => 'localhost:8080' => 'LeadtoolsServicesHost' then copy the path of the file and replace [PATH] with it.

  9. Save in Notepad to XML with any name such as 'LEAD_OCR_Service.xml' in a directory of your choice.

  10. In the 'Projects' window of the 'OCRImage' project, browse to 'Web Service References', Right-Click on the 'OCRService.svc' and choose 'Edit Web Service Attributes'.
  11. In the 'WSDL Customization Tab', expand 'External Binding Files' and Press 'Add'. Press yes, locate the 'LEAD_OCR_ Service.xml' and choose OK.
  12. In '' add the following code after 'package ocrimage;':



  13. Add the following code in the Main function:


       // Call Web Service Operation 
       OcrService service = new OcrService(); 
       IOcrService port = service.getBasicHttpBindingIOcrService(); 
       // TODO initialize WS operation arguments here 
       FileBinaryData sourceFile = new FileBinaryData(); 
       FileBinaryData destData = new FileBinaryData(); 
       destData.setFileName("\\\\MyMachine \\SharedFolder\\OCR1.txt"); 
       DocumentConvertOptions convertOptions = new DocumentConvertOptions(); 
       RecognizeRequest parameters = new RecognizeRequest(); 
    catch (Exception ex) 
       // TODO handle custom exceptions here 


    • MyMachine is the name of the Machine you are running the application from if you are performing an OCR on a disk file.
    • The OCR Service must have write/read access to 'MyMachine'.
  14. Compile and Run the application.
Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document