【发布时间】:2015-07-07 22:27:11
【问题描述】:
这是我的场景:
一个启用了 FormsAuthentication 的 SignalR 服务器和一个端点 (WebAPI2),我可以在其中发布身份验证请求以获取身份验证票 (Cookie)。
将向此服务器发出身份验证请求的 Android 应用程序获取身份验证 cookie 并使用该 cookie 连接到 signalR HUB,作为经过身份验证的用户。
使用 ServerSentEventsTransport 时,一切正常,客户端可以验证并连接到服务器,没有问题。
但是,当使用 WebsocketTransport 时,连接不会完成。日志波纹管显示它挂在哪里:
HubConnection - Creating hub proxy: messagehub
HubProxy MessageHub - Subscribe to event messageReceived
HubProxy MessageHub - Creating new subscription for: messagereceived
HubConnection - Entered startLock in start
: null
HubConnection - Start the connection, using AutomaticTransport transport
HubConnection - Start negotiation
: null
AutomaticTransport - Start the negotiation with the server
HubConnection - Getting connection data: [{"name":"messagehub"}]
HubConnection - Getting connection data: [{"name":"messagehub"}]
AutomaticTransport - Execute the request
Create new thread for HTTP Connection
Execute the HTTP Request
URL: http://www.voicenap.com/signalr/negotiate?clientProtocol=1.3&connectionData=%5B%7B%22name%22%3A%22messagehub%22%7D%5D&
VERB: GET
Header User-Agent: SignalR (lang=Java; os=windows 7; version=2.0)
CONTENT: null
Request executed
AutomaticTransport - Response received
AutomaticTransport - Read response data to the end
AutomaticTransport - Trigger onSuccess with negotiation data: {"Url":"/signalr","ConnectionToken":"gJYpQm9SxUDpk9mzxZkpn5VrojtfHdX4wiJovcDHR7yYttg4DVgpy9EU9JDNOKjndRhctwfCHvg7HFaTOAUZ5tdpi7wL8sq4me6TgRycPrvjxb3CfyEYMHK3nDQY/y7e","ConnectionId":"2c97c4e9-28dc-4ac0-9859-b73c6536d01b","KeepAliveTimeout":20.0,"DisconnectTimeout":30.0,"ConnectionTimeout":110.0,"TryWebSockets":true,"ProtocolVersion":"1.3","TransportConnectTimeout":5.0,"LongPollDelay":0.0}
HubConnection - Negotiation completed
HubConnection - ConnectionId: 2c97c4e9-28dc-4ac0-9859-b73c6536d01b
HubConnection - ConnectionToken: gJYpQm9SxUDpk9mzxZkpn5VrojtfHdX4wiJovcDHR7yYttg4DVgpy9EU9JDNOKjndRhctwfCHvg7HFaTOAUZ5tdpi7wL8sq4me6TgRycPrvjxb3CfyEYMHK3nDQY/y7e
HubConnection - Keep alive timeout: 20.0
HubConnection - Entered startLock in startTransport
HubConnection - Starting the transport
HubConnection - Starting transport for InitialConnection
HubConnection - Getting connection data: [{"name":"messagehub"}]
HubConnection - Getting connection data: [{"name":"messagehub"}]
有趣的一点是,如果我从web.config 中删除<authentication mode="Forms"/> 配置,连接会成功建立,但没有身份验证数据(如预期的那样)
是否有人可以在需要身份验证和授权(使用 HUB 上的 Authorize 属性)的 HUB 上成功实现 Android SignalR 客户端,使用 Websockets?如果是,怎么做???
谢谢!!
【问题讨论】:
标签: android asp.net websocket signalr signalr-hub