Skip to content

Commit ba2e143

Browse files
authored
Merge pull request #274 from bjorg/issue_262
Blazor WebAssembly support: added try-catch for unsupported properties
2 parents b838003 + d1199a1 commit ba2e143

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,9 @@ subscription.Dispose();
139139
* [GitHub GraphQL API Docs](https://developer.github.com/v4/guides/forming-calls/)
140140
* [GitHub GraphQL Explorer](https://developer.github.com/v4/explorer/)
141141
* [GitHub GraphQL Endpoint](https://api.github.com/graphql)
142+
143+
## Blazor WebAssembly Limitations
144+
145+
Blazor WebAssembly differs from other platforms as it does not support all features of other .NET runtime implementations. For instance, the following WebSocket options properties are not supported and will not be set:
146+
* [ClientCertificates](https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocketoptions.clientcertificates?view=netcore-3.1#System_Net_WebSockets_ClientWebSocketOptions_ClientCertificates)
147+
* [UseDefaultCredentials](https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocketoptions.usedefaultcredentials?view=netcore-3.1)

src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,22 @@ public Task InitializeWebSocket()
407407
#else
408408
_clientWebSocket = new ClientWebSocket();
409409
_clientWebSocket.Options.AddSubProtocol("graphql-ws");
410-
_clientWebSocket.Options.ClientCertificates = ((HttpClientHandler)Options.HttpMessageHandler).ClientCertificates;
411-
_clientWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)Options.HttpMessageHandler).UseDefaultCredentials;
410+
try
411+
{
412+
_clientWebSocket.Options.ClientCertificates = ((HttpClientHandler)Options.HttpMessageHandler).ClientCertificates;
413+
}
414+
catch (PlatformNotSupportedException)
415+
{
416+
Debug.WriteLine("unable to set Options.ClientCertificates property; platform does not support it");
417+
}
418+
try
419+
{
420+
_clientWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)Options.HttpMessageHandler).UseDefaultCredentials;
421+
}
422+
catch (PlatformNotSupportedException)
423+
{
424+
Debug.WriteLine("unable to set Options.UseDefaultCredentials property; platform does not support it");
425+
}
412426
Options.ConfigureWebsocketOptions(_clientWebSocket.Options);
413427
#endif
414428
return _initializeWebSocketTask = ConnectAsync(_internalCancellationToken);

0 commit comments

Comments
 (0)