With the release of Silverlight 4 came the support to communicate with COM objects when a Silverlight application is run out of browser with elevated trust. This allows you to communicate with any COM object installed on the users/client's machine.
In order to scan from a scanner on the client's machine, you must be able to communicate with the scanner's driver, which is also found on the client's machine.
As of this article's submission date, there is no COM object that allows you to communicate with Twain that is already installed with Windows or that is available through a Windows Update.
Therefore, it is up to you, the developer, to create such a COM object and deploy it to the client's machine through whatever means available (Cabinet File, MSI installer, etc...)
The attached solution shows you how to create this COM object using LEADTOOLS's .NET classes.
The TwainCOMWrapper project wraps our TwainSession .NET class in a UserControl and gives it a GUID and ProgID. The project settings are adjusted also. Under Application | Assembly Information dialog, ensure "Make assembly COM-Visible" is checked. Under Build make sure "Register for COM interop" is checked to register the class on your development machine.
The OutOfBrowserApplication is a Silverlight 4 Application setup to run out of brower with elevated trust. In the project settings, under Silverlight, ensure "Enable running application out of the browser" is checked. Also, click on the "Out of Browser Setting" button. In the next dialog, ensure "Require elevated trust when running outside the browser" is checked. This will allow the Silverlight application to create COM objects on the user's machine.
In the Silverlight code you will create an instance of the COM object using the AutomationFactory.CreateObject function. You assign the returned value to a dynamic variable. Please note the "dynamic" keyword is available by adding a reference to the "Microsoft.CSharp.dll" to your references. You can then use your COM object like any other COM object in .NET.
The COM object also contains an AcquirePage event. The Silverlight project shows you also how to handle this event using a delegate and dynamic objects.
The code for creating the COM object can be found in the App.xaml.cs file under the Application_Startup event. The application ensures Twain is available, and if so, creates the object and passes it to the MainPage. The MainPage then uses the object. When the application is closed we handle the Application_Exit to close the Twain session.
Please note this is not a finished application but merely a sample to help you get started with adding Twain support to your Silverlight application.
For information about accessing COM through Silverlight 4, and to see a video demonstrating how to setup your Silverlight project to access COM., please take a look at the MSDN video found here:
http://www.silverlight.net/learn/videos/all/com-object-access-trusted-applications/
With the release of Silverlight 5, you can now have In Browser Applications access the file system which will allow you to access COM objects from within the browser. See the following Microsoft article to learn how this can be done:
http://msdn.microsoft.com/en-us/library/ee721083(v=vs.95).aspxTravis Montgomery
Senior Sales Engineer