SignalR server error "ConnectionId is in the wrong format". with SignalR-ObjC library

Before asking a separate question, I asked about it many times and added a comment to the already existing stackoverflow question .

I have a SignalR Hub (tried both v. 1.1.3 and 2.0.0-rc) on my server with the code below:

[HubName("TestHub")] public class TestHub : Hub { [Authorize] public void TestMethod(string test) { //some stuff here Clients.Caller.NotifyOnTestCompleted(); } } 

The problem persists if I remove the Authorize attribute.

And in my iOS client, I'm trying to call it using the code below:

  SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:_baseURL]; SRHubProxy *hubProxy = [hubConnection createHubProxy:@"TestHub"]; [hubProxy on:@"NotifyOnTestCompleted" perform:self selector:@selector(stopConnection)]; hubConnection.started = ^{ [hubProxy invoke:@"TestMethod" withArgs:@[@"test"]]; }; //received, error handling [hubConnection start]; 

When the application starts, the user will not be logged in and there is no open SignalR connection. Users register by calling the Login service on a server that uses the WebSecurity.Login method. If the login service returns success, I then make the above call in the SignalR Hub, and I get a 500 server error with the description "ConnectionId is in the wrong format."

The full stacktrace server stack is as follows:

  Exception information: Exception type: InvalidOperationException Exception message: The ConnectionId is in the incorrect format. at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(IDictionary`2 environment) at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Request information: Request URL: http://myserverip/signalr/signalr/connect?transport=webSockets&connectionToken=axJs EQMZxpmUopL36owSUkdhNs85E0fyB2XvV5R5znZfXYI/CiPbTRQ3kASc3 mq60cLkZU7coYo1P fbC0U1LR2rI6WIvCNIMOmv/mHut/Unt9mX3XFkQb053DmWgCan5zHA==&connectionData=[{"Name":"testhub"}] Request path: /signalr/signalr/connect User host address: User: Is authenticated: False Authentication Type: Thread account name: IIS APPPOOL\DefaultAppPool Thread information: Thread ID: 14 Thread account name: IIS APPPOOL\DefaultAppPool Is impersonating: True Stack trace: at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(IDictionary`2 environment) at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) signalr / signalr / connect transport = webSockets & connectionToken = axJs EQMZxpmUopL36owSUkdhNs85E0fyB2XvV5R5znZfXYI / CiPbTRQ3kASc3 mq60cLkZU7coYo1P fbC0U1LR2rI6WIvCNIMOmv / mHut / Unt9mX3XFkQb053DmWgCan5zHA == & connectionData = [{ "Name": "testhub"}]?  Exception information: Exception type: InvalidOperationException Exception message: The ConnectionId is in the incorrect format. at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(IDictionary`2 environment) at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Request information: Request URL: http://myserverip/signalr/signalr/connect?transport=webSockets&connectionToken=axJs EQMZxpmUopL36owSUkdhNs85E0fyB2XvV5R5znZfXYI/CiPbTRQ3kASc3 mq60cLkZU7coYo1P fbC0U1LR2rI6WIvCNIMOmv/mHut/Unt9mX3XFkQb053DmWgCan5zHA==&connectionData=[{"Name":"testhub"}] Request path: /signalr/signalr/connect User host address: User: Is authenticated: False Authentication Type: Thread account name: IIS APPPOOL\DefaultAppPool Thread information: Thread ID: 14 Thread account name: IIS APPPOOL\DefaultAppPool Is impersonating: True Stack trace: at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(IDictionary`2 environment) at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

I understand that this is some identification and inconsistency of user identity, but so far I have not found a way to solve it. All other questions involve stopping the open connection when the user ID changes, but, as I mentioned above, I do not have an open connection until the login successfully.

Any help would be greatly appreciated. Thanks.

+6
source share
3 answers

Here is what I found, I'm trying to create a Flex / AS3 client for signalR. It uses only websites, but for my work I control both ends of the system, so I know that my backend will support it.

Anyway, the trick to get around this for me is the connectionToken encoding. The server side signal code is trying to parse the connection identifier from the token. When you receive a token from the server, it comes as part of negotiating negotiation, when you try to send it back, you must remove the "/" and "+" characters and encode them as% 2F and% 2B, respectively. In AS3, escape code methods or other equivalent URL encoding methods left slashes, presumably because they are a valid url character, but since the value is passed to querystring, it must be encoded.

As soon as I did this, I stopped getting a 500 server error (ConnectionId is in the wrong format) and the socket is open and I received messages.

Hope this helps.

Jason

+2
source

It looks like you are using https://github.com/DyKnow/SignalR-ObjC be sure to use the feature-2.0.0.beta1 branch until it is pulled into master.

+2
source

We had a similar problem. Disabling cryptographic functions for connection tokens is fixed.

Sorry, I can’t help further, since I work with iOS end, not with .net end.

+1
source

Source: https://habr.com/ru/post/954491/


All Articles