Answered by:
WebSocket exception while attempt to hub connect

Question
-
User1338262655 posted
I completely confused in signalR. I tried to repeat this example, but every time did catch Websocket exception. My Hub class looks like
public class ContosoChatHub : Hub { public void NewContosoChatMessage(string name, string message) { Clients.All.addContosoChatMessageToPage(name, message); } }
and client JS code like :
var connection = $.hubConnection(); var contosoChatHubProxy = connection.createHubProxy('contosoChatHub'); contosoChatHubProxy.on('addContosoChatMessageToPage', function (name, message) { console.log(name + ' ' + message); }); connection.start().done(function () { $('#sendButton').click(function () { contosoChatHubProxy.invoke('newContosoChatMessage', $('#userInput').val(), $('#messageInput').val()); $('#messageInput').val('').focus(); }); });
I use Windows 10 and iis v10.0.1734. Unfortunately, whatever I do, every time failed to connect to server hub. Exceptions :
I have no idea, how to solve this issue. Help, please. Thank you.
Sunday, March 10, 2019 6:49 PM
Answers
-
User61956409 posted
Hi Alter,
I did a same test to establish a connection without the generated proxy, the code work well on my side.
var connection = $.hubConnection(); var contosoChatHubProxy = connection.createHubProxy('contosoChatHub'); contosoChatHubProxy.on('addContosoChatMessageToPage', function (userName, message) { console.log(userName + ' ' + message); }); connection.start().done(function () { console.log('Now connected, connection ID=' + connection.id); $('#sendButton').click(function () { contosoChatHubProxy.invoke('newContosoChatMessage', "fei han", $('#messageInput').val()); $('#messageInput').val('').focus(); }); }).fail(function () { console.log('Could not connect'); });
Test Result:
The code that you provided seems ok. As mgebhard suggested, if possible, please share a reproducible sample, so that we can troubleshoot the issue better.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 11, 2019 2:53 AM
All replies
-
User475983607 posted
I completely confused in signalR. I tried to repeat this example, but every time did catch Websocket exception. My Hub class looks like public class ContosoChatHub : Hub { public void NewContosoChatMessage(string name, string message) { Clients.All.addContosoChatMessageToPage(name, message); } }
and client JS code like :
var connection = $.hubConnection(); var contosoChatHubProxy = connection.createHubProxy('contosoChatHub'); contosoChatHubProxy.on('addContosoChatMessageToPage', function (name, message) { console.log(name + ' ' + message); }); connection.start().done(function () { $('#sendButton').click(function () { contosoChatHubProxy.invoke('newContosoChatMessage', $('#userInput').val(), $('#messageInput').val()); $('#messageInput').val('').focus(); }); });
I use Windows 10 and iis v10.0.1734. Unfortunately, whatever I do, every time failed to connect to server hub. Exceptions :
I have no idea, how to solve this issue. Help, please. Thank you.
There is simply not enough code shown to determine if you are following the tutorial correctly.
Can you post code that reproduces this issue?
Sunday, March 10, 2019 7:03 PM -
User1338262655 posted
all my Code did posted above. did you mean `startup` class Code?
Sunday, March 10, 2019 7:15 PM -
User61956409 posted
Hi Alter,
I did a same test to establish a connection without the generated proxy, the code work well on my side.
var connection = $.hubConnection(); var contosoChatHubProxy = connection.createHubProxy('contosoChatHub'); contosoChatHubProxy.on('addContosoChatMessageToPage', function (userName, message) { console.log(userName + ' ' + message); }); connection.start().done(function () { console.log('Now connected, connection ID=' + connection.id); $('#sendButton').click(function () { contosoChatHubProxy.invoke('newContosoChatMessage', "fei han", $('#messageInput').val()); $('#messageInput').val('').focus(); }); }).fail(function () { console.log('Could not connect'); });
Test Result:
The code that you provided seems ok. As mgebhard suggested, if possible, please share a reproducible sample, so that we can troubleshoot the issue better.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 11, 2019 2:53 AM -
User1338262655 posted
Did you mean some test *.proj or *.sln ? Yes, It's possible, I just need some time. Meanwhile, can you confirm, you using IIS Express on local machine?
My Local machine work under Windows 10. And WebSockets protocol is enabled in windows features.Monday, March 11, 2019 9:10 AM