У меня есть приложение C # для Windows со встроенным сканером, работающее с WebSocket с помощью команды websocketd --port=7777 TarasolEdgeScanner.exe
.
У меня есть веб-приложение ASP.NET, открывающее вышеуказанное приложение Windows с помощью команды js var ws = new WebSocket('ws://127.0.0.1:8085/');
приложение открывается нормально.
Я использую библиотеку Microsoft Windows Imaging Acquisition (WIA) для сканирования документов в приложении Windows.Все работает нормально, когда я открываю приложение Windows в одиночку.Но когда я открываю его с помощью команды веб-сокета, я получаю следующее исключение:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at TarasolEdgeScanner.ScanForm.StartScan()
at TarasolEdgeScanner.ScanForm.btnScan_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
TarasolEdgeScanner
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/TarasolEdgeScanner.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Interop.WIA
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/Interop.WIA.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Я попытался отладить, но мне не удалось.Это не отладка.Пожалуйста, помогите.
Код работает хорошо, когда я запускаю его отдельно без формы ASP.NET
// Create a DeviceManager instance
var deviceManager = new DeviceManager();
// Create an empty variable to store the scanner instance
DeviceInfo firstScannerAvailable = null;
// Loop through the list of devices to choose the first available
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
{
// Skip the device if it's not a scanner
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
{
continue;
}
firstScannerAvailable = deviceManager.DeviceInfos[i];
break;
}
// Show a message and stop if no connected scanners found
if (firstScannerAvailable == null)
{
MessageBox.Show("No connected scanners found!");
return;
}
// Connect to the first available scanner
var device = firstScannerAvailable.Connect();
// Select the scanner
var scannerItem = device.Items[1];
// Retrieve an image in JPEG format and store it into a variable
//var imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatJPEG); //This scans without showing progress
CommonDialogClass dlg = new CommonDialogClass(); //To show scanning progress
//The exception raised in below line
object scanResult = dlg.ShowTransfer(scannerItem, WIA.FormatID.wiaFormatJPEG, false);