SignalR Unexpected character encountered while parsing value: <

末鹿安然 提交于 2020-01-04 04:38:05

问题


I am using a WinRT client. I receive this exception when I try to send a message.

Unexpected character encountered while parsing value: <.

The problem occurs when you send an object to the hub, and the object is not defined on the hub. The object is a Bindable object (ViewModel). I don't want to include all the property notify change stuff on the web project.

Client Code

return Proxy.Invoke("PlayerUpdate", sessionData);

Try one was to have the hub accept an 'object' parameter

public async Task PlayerUpdate(string group, object sessionData)
{
 await Clients[group].PlayerUpdate(sessionData);
}

Try two was to have the hub accept an (json) 'string' parameter

public async Task PlayerUpdate(string group, string sessionData)
{
 await Clients[group].PlayerUpdate(sessionData);
}

Try three was to pre-serialize the object client side

var str = JsonConvert.SerializeObject(refresh);
return Proxy.Invoke("PlayerUpdate", str);

Nothing is working. Plan 4 is to define some data transfer objects in a shared libarary to send. I really dont want to do that as It will about double my code.


回答1:


Solved.

My repo project was fine, so I concluded that something else was the matter.

After some experimentation I discovered the real problem was that I had incorrect parameters in my HUB method. Simply put, I was sending 2 parameters when my hub methods only accepted 1.

Thanks for the interest, sorry for the confusion. Perhaps a better exception message is in order?




回答2:


This seems like an internal error with SignalR and I don't think anyone's going to be able to help you with this on StackOverflow. You should file an issue with the SignalR GitHub project.




回答3:


My client was receiving this exception only when the site URL contained a trailing Default.aspx. The following cleaned up the HubConnection URL parameter:

string serverUri = new Uri(HtmlPage.Document.DocumentUri, ".").ToString();
HubConnection connection = new HubConnection(serverUri, true);


来源:https://stackoverflow.com/questions/12730096/signalr-unexpected-character-encountered-while-parsing-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!