danielklecha / SharpIppNextServer

IPP printer (web app) based on SharpIppNext library.
MIT License
1 stars 0 forks source link

When Hosting with IIS, AllowSynchronousIO error #1

Open andygarratt opened 2 days ago

andygarratt commented 2 days ago

When hosting on IIS you get the below error in event viewer

Category: SharpIppNextServer.Services.PrinterService EventId: 0 SpanId: 6673d071b1c75b6e TraceId: 827d6ed632185a23ee6277917614f5f9 ParentId: 0000000000000000 RequestId: 80008aae-0001-e400-b63f-84710c7967bb RequestPath: /

Unable to process request

Exception: System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead. at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.Stream.Read(Span1 buffer) at System.IO.Stream.ReadAtLeastCore(Span1 buffer, Int32 minimumBytes, Boolean throwOnEndOfStream) at System.IO.BinaryReader.InternalRead(Int32 numBytes) at System.IO.BinaryReader.ReadInt16() at SharpIpp.Protocol.Extensions.BinaryReaderExtensions.ReadInt16BigEndian(BinaryReader reader) at SharpIpp.Protocol.IppProtocol.ReadIppRequestAsync(BinaryReader reader, CancellationToken cancellationToken) at SharpIpp.Protocol.IppProtocol.ReadIppRequestAsync(Stream stream, CancellationToken cancellationToken) at SharpIpp.SharpIppServer.ReceiveRequestAsync(Stream stream, CancellationToken cancellationToken) at SharpIppNextServer.Services.PrinterService.ProcessRequestAsync(Stream inputStream, Stream outputStream) in E:\GitHub\SharpIppNextServer\SharpIppNextServer\Services\PrinterService.cs:line 34

This can be resolved by adding

.Configure(options => options.AllowSynchronousIO = true)

next to the Kestrel option.

ipptool test then passes:

D:\ipptool>ipptool -t ipp://192.168.0.77:631/ ipp-1.1.test "ipp-1.1.test": RFC 2911 section 3.1.1: Bad request-id value 0 [PASS] RFC 2911 section 3.1.4: No Operation Attributes [PASS] RFC 2911 section 3.1.4: attributes-charset [PASS] RFC 2911 section 3.1.4: attributes-natural-language [PASS] RFC 2911 section 3.1.4: attributes-natural-language + attributes-cha [PASS] RFC 2911 section 3.1.4: attributes-charset + attributes-natural-lang [PASS] RFC 2911 section 3.1.8: Unsupported IPP version 0.0 [PASS] RFC 2911 section 3.2: No printer-uri operation attribute [PASS] ipptool: Filename "$filename" on line 155 cannot be read. ipptool: Filename mapped to "".

Summary: 8 tests, 8 passed, 0 failed, 0 skipped Score: 100%

However I still cannot add a queue on Windows, I get an error saying Windows couldn't connect to the printer.

image

Cheers, Andy

andygarratt commented 2 days ago

Below is better output from the ipptool test

D:\ipptool>ipptool -t ipp://192.168.0.77:631/ ipp-1.1.test "ipp-1.1.test": RFC 2911 section 3.1.1: Bad request-id value 0 [PASS] RFC 2911 section 3.1.4: No Operation Attributes [PASS] RFC 2911 section 3.1.4: attributes-charset [PASS] RFC 2911 section 3.1.4: attributes-natural-language [PASS] RFC 2911 section 3.1.4: attributes-natural-language + attributes-cha [PASS] RFC 2911 section 3.1.4: attributes-charset + attributes-natural-lang [PASS] RFC 2911 section 3.1.8: Unsupported IPP version 0.0 [PASS] RFC 2911 section 3.2: No printer-uri operation attribute [PASS] RFC 2911 section 3.2.1: Print-Job Operation [PASS] RFC 2911 section 3.2.3: Validate-Job Operation [PASS] RFC 2911 section 3.2.5: Get-Printer-Attributes Operation (default) [PASS] color-supported (boolean) = true compression-supported (keyword) = none document-format-supported (mimeMediaType) = application/pdf ipp-versions-supported (1setOf keyword) = 1.0,1.1 operations-supported (1setOf enum) = Print-Job,Print-URI,Validate-Job,Create-Job,Send-Document,Send-URI,Cancel-Job,Get-Job-Attributes,Get-Jobs,Get-Printer-Attributes,Hold-Job,Release-Job,Restart-Job,Pause-Printer,Resume-Printer pages-per-minute (integer) = 20 pages-per-minute-color (integer) = 20 printer-uri-supported (uri) = ipp://192.168.0.77:631/ reference-uri-schemes-supported (1setOf uriScheme) = ftp,http,https uri-authentication-supported (keyword) = none uri-security-supported (keyword) = none media-supported (keyword) = iso_a4_210x297mm print-quality-supported (enum) = high RFC 2911 section 3.2.5: Get-Printer-Attributes Operation (requested- [PASS] RFC 2911 section 3.2.6: Get-Jobs Operation (default) [PASS] RFC 2911 section 3.2.6: Get-Jobs Operation (requested-attributes) [FAIL] RECEIVED: 634 bytes in response status-code = successful-ok (successful-ok) attributes-charset (charset) = utf-8 attributes-natural-language (naturalLanguage) = en copies (integer) = 1 date-time-at-creation (dateTime) = 2024-09-20T16:01:26Z document-format (mimeMediaType) = application/pdf document-name (nameWithoutLanguage) = document-a4.pdf finishings (enum) = none ipp-attribute-fidelity (boolean) = false job-id (integer) = 20001 job-uri (uri) = ipp://192.168.0.77:631//20001 job-name (nameWithoutLanguage) = document-a4.pdf job-originating-user-name (nameWithoutLanguage) = AndyGarratt job-printer-up-time (integer) = 252 job-printer-uri (uri) = ipp://192.168.0.77:631/ job-state (enum) = pending job-state-reasons (keyword) = none media (keyword) = iso_a4_210x297mm orientation-requested (enum) = portrait printer-resolution (resolution) = 600x600dpi print-quality (enum) = high sides (keyword) = one-sided time-at-creation (integer) = 252 EXPECTED: time-at-processing EXPECTED: time-at-completed

Summary: 14 tests, 13 passed, 1 failed, 0 skipped Score: 92%

andygarratt commented 2 days ago

The below event viewer log I believe related to the last ipptool test

Category: SharpIppNextServer.Services.PrinterService EventId: 0 SpanId: 9201ae9cc660ff1b TraceId: b066538a503b829d1146c91e9f3830c9 ParentId: 0000000000000000 RequestId: 8000dde9-0001-ed00-b63f-84710c7967bb RequestPath: /

Unable to process request

Exception: SharpIpp.Exceptions.IppRequestException: No printer-uri operation attribute at SharpIpp.SharpIppServer.ValidateRawRequest(IIppRequestMessage request) at SharpIpp.SharpIppServer.ReceiveRequestAsync(Stream stream, CancellationToken cancellationToken) at SharpIppNextServer.Services.PrinterService.ProcessRequestAsync(Stream inputStream, Stream outputStream) in E:\GitHub\SharpIppNextServer\SharpIppNextServer\Services\PrinterService.cs:line 34 RequestMessage: SharpIpp.Protocol.Models.IppRequestMessage

gmuth commented 12 hours ago

I don't think this ipptool test issue is related to your "add to windows" issue or log message you found. They look like 3 different issues to me.

The failing test is about some "time-at-..." job attributes required by spec. This response is part of a print-workflow. However your windows issue is related to a "setup-printer" workflow where other operations are used.

ipptests do not test windows interoperability. They enable developers of cups to test their implementation agains the IPP spec of the printer working group. Anyway RFC2911 is now deprecated - looks like you have a very old CUPS installation at hand. (https://github.com/OpenPrinting/cups/blob/master/examples/ipp-2.0.test uses IPP 2.0 and refers to RFC 8011)

I think your issue is not related to "Hosting with IIS". It looks more like a printer setup issue related to the workflow the client (please specify) is trying to complete. I'll open another ticket to get a better understanding of what this server is about.

andygarratt commented 1 hour ago

@gmuth I think there are two issues here, one is for hosting on IIS, where you have to add the below link to enable it to work, it works well with that line added though

.Configure(options => options.AllowSynchronousIO = true)

The second issue related to adding a print using MS Windows, using the powershell ass-printer works fine, the add printer wizard however does not, like you say.