我正在使用Blazor WebAssembly,并尝试使用Microsoft.AspNet.SignalR.Client连接到SignalR服务器(ASP.NET SignalR,而不是ASP.NET Core SignalR)。代码如下:
var hubConnection = new HubConnection(url, queryString);
await hubConnection.Start();
我收到以下异常:
System.PlatformNotSupportedException: Property Credentials is not supported. blazor.webassembly.js:1:37722
at System.Net.Http.HttpClientHandler.set_Credentials (System.Net.ICredentials value) <0x3c223e0 + 0x0000c> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpHandler..ctor (Microsoft.AspNet.SignalR.Client.IConnection connection) <0x3c1f850 + 0x00040> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.CreateHandler () <0x3c1f000 + 0x00006> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.Initialize (Microsoft.AspNet.SignalR.Client.IConnection connection) <0x3c1eca8 + 0x00010> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.GetNegotiationResponse (Microsoft.AspNet.SignalR.Client.Http.IHttpClient httpClient, Microsoft.AspNet.SignalR.Client.IConnection connection, System.String connectionData) <0x3c1d5c0 + 0x0004c> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Transports.AutoTransport.GetNegotiateResponse (Microsoft.AspNet.SignalR.Client.IConnection connection, System.String connectionData) <0x3c1cc58 + 0x0001e> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Transports.AutoTransport.Negotiate (Microsoft.AspNet.SignalR.Client.IConnection connection, System.String connectionData) <0x3c1cb58 + 0x0000e> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Connection+<>c__DisplayClass153_0.<Negotiate>g__StartNegotiation|1 () <0x3c1c9b0 + 0x0001a> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Connection.Negotiate (Microsoft.AspNet.SignalR.Client.Transports.IClientTransport transport) <0x39ffec0 + 0x0003c> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Connection.Start (Microsoft.AspNet.SignalR.Client.Transports.IClientTransport transport) <0x39e6f10 + 0x000e6> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Connection.Start (Microsoft.AspNet.SignalR.Client.Http.IHttpClient httpClient) <0x39da2a8 + 0x0000e> in <filename unknown>:0 blazor.webassembly.js:1:37722
at Microsoft.AspNet.SignalR.Client.Connection.Start () <0x39da1e8 + 0x0000c> in <filename unknown>:0
我没有设置Credentials
的{{1}}属性,它是hubConnection
。据错误消息所知,客户端尝试设置null
属性,而Blazor不支持此属性。我该怎么做才能避免这种情况?我不需要使用Credentials
,我在查询字符串中传递了所有服务器需求。相同的代码在控制台应用程序中可以正常工作。
答案 0 :(得分:0)
我设法克服了这种情况,实现了我自己的 InputStream is = null;
PDFDocument document = new PDFDocument();
document.load(inputStream);
System.out.println("PDF file loaded...");
SimpleRenderer renderer = new SimpleRenderer();
renderer.setResolution(dpi);
List<Image> images = renderer.render(document);
for (int i = 0; i < images.size(); i++) {
RenderedImage renderedImage = (RenderedImage) images.get(i);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(renderedImage, "png", outputStream);
is = new ByteArrayInputStream(outputStream.toByteArray());
outputStream.flush();
outputStream.close();
//is upload inputstream to google cloud
uploadMobileFileToBucket("some file path", is)
}
,但未设置HttpClient
的问题,但是我仍然遇到其他与运行时不兼容有关的错误。似乎Microsoft.AspNet.SignalR.Client在Blazor / Mono中无法正常工作。