问题描述
我正在使用WinRT客户端.当我尝试发送消息时,我收到此异常.
I am using a WinRT client. I receive this exception when I try to send a message.
解析值时遇到意外字符:<.
Unexpected character encountered while parsing value: <.
当您将对象发送到集线器,并且该对象未在集线器上定义时,会发生问题.该对象是可绑定对象(ViewModel).我不想在Web项目中包含所有属性通知更改内容.
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.
客户代码
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);
}
尝试两个是让集线器接受一个(json)'string'参数
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);
什么都没有.计划4是在共享库中定义一些要发送的数据传输对象.我真的不想这样做,因为它将使我的代码加倍.
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.
推荐答案
已解决.
我的回购项目很好,所以我得出结论是其他问题.
My repo project was fine, so I concluded that something else was the matter.
经过一些实验,我发现真正的问题是我的HUB方法中的参数不正确.简而言之,当我的集线器方法仅接受1个参数时,我正在发送2个参数.
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?
这篇关于SignalR解析值时遇到意外字符:<的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!