Yesterday I wrote a blog post about the possibilities & problems around hardware integration from Silverlight using the sockets capabilities. This evening whilst I was watching some television I started playing with this idea.
In the end I created a simple HttpListener (in a console application) which listens on port 8888 which serves up the client access policy file. In a subsequent WebClient request from the Silverlight application a call the the Windows Image Acquisition (WIA) API is used to grab an image and transfer it into the Silverlight application.
You can download my demo code over at MSDN. The reason I’ve been playing with this stuff is that I’d like to deliver a web-based Point-of-Sale experience but there are some requirements for hardware integration at particular workstations.
With a little bit more work I think it might be possible to come up with a really elegant solution that works across multiple sites. So if you were building a Silverlight application and you wanted to support some image capture you could just launch a hyperlink to a ClickOnce application (from a trusted source) which would download a small footprint HTTP server which would provide the client-side integration.
One of the key requirements would be security so you could set it up so that each time an application requested a scan it could pop up and approval dialog for that domain. That would then tweak the access policy file that it dished up and Silverlight would then make the actual request to scan the image.