如何使用signalR

时间:2016-05-03 11:05:02

标签: android asp.net asp.net-mvc signalr

我的Android代码是:

mHubProxy.on( "PushContentsToClient", new SubscriptionHandler1<ChatMessageResponsePOCO[]>() {
            @Override
            public void run(final ChatMessageResponsePOCO[] msgs) {
                    MainActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            Log.d("MGR_ERROR",""+msgs.length);
                        }
                    });
                }

        }, ChatMessageResponsePOCO[].class);

和我的班级:

public class ChatMessageResponsePOCO {
    public long ChatId;
    public int ChatAck;
    public String MobileNumber;
    public String ChatContent;
    public Date ChatDatetime;
    public int MessageType;

}

服务器端代码是:

Clients.Client(connectionToken).PushContentsToClient(chatMessageResponseListDTO);

服务器端实体:

 public class ChatMessageResponsePOCO
    {
        public Int64 ChatId { get; set; }
        public int ChatAck { get; set; }
        public string MobileNumber { get; set; }
        public string ChatContent { get; set; }
        public DateTime ChatDatetime { get; set; }
        public int MessageType { get; set; }
    }

它对String工作正常但对List<ChatMessageResponsePOCO>没有响应。请帮忙。

1 个答案:

答案 0 :(得分:0)

ChatMessageResponsePOCO这不是一个数组。这是一堂课。所以做这样的事情

mHubProxy.on( "PushContentsToClient", new SubscriptionHandler1<ChatMessageResponsePOCO>() {
        @Override
        public void run(final ChatMessageResponsePOCO msgs) {
                MainActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Log.d("Mobile No ","" + msgs.MobileNumber); //Example
                        Log.d("MGR_ERROR",""+msgs.length);
                    }
                });
            }

    }, ChatMessageResponsePOCO.class);