c# - Signalr .net client -


so im try connect service in c#, have no control on service , cant change there, , nor have documentation :(

so im trying change javascript signalr client .net (but not of it)

    $(document).ready(function () {          //url of queues api         var queueapi = "/ccmwa/api/v1/queues/";          //signalr connection         $.connection.hub.logging = true;         var myhub = $.connection.queuestatistics;          //wire event handlers         myhub.client.onqueuenowdataupdate = function (data) {             //alert(data);             var data = json.stringify(data);             $('#messages').append('<li>server: received onqueuenowdataupdate</li>');             $('#getnowresults').text(data);         };          //wire event handlers         myhub.client.onqueueconversationupdate = function (data) {             //alert(data);             var data = json.stringify(data);             $('#messages').append('<li>server: received onqueueconversationupdate</li>');             $('#getconversationresults').text(data);         };          //wire event handlers         myhub.client.connected = function () {             $('#messages').append('<li>server: says connected</li>');                         };          //wire event handlers         myhub.client.reconnected = function () {             $('#messages').append('<li>server: says reconnected</li>');         };          //start         $.connection.hub.start()                         .done(function () {                             logmessage("client: connection started");                             //myhub.server.joinfoo()                             //     .done(function () {                             //         logmessage("client: sent join server");                             //     })                         })                         .fail(function () {                             logmessage("client: not connect server");                         });          $("#startnow").click(function () {             var id = $("#queuenowid").val();              myhub.server.startqueuestatemonitor(id)                .done(function () {                    $('#messages').append('<li>client: addmonitor ' + id + '</li>');                })                .fail(function () {                    $('#messages').append('<li>client: failed send addmonitor</li>');                });          });          function logmessage(message)         {             $('#messages').append(message);         }          $("#stopnow").click(function () {             var id = $("#queuenowid").val();              myhub.server.stopqueuestatemonitor(id)                .done(function () {                    $('#messages').append('<li>client: removemonitor ' + id + '</li>');                })                .fail(function () {                    $('#messages').append('<li>client: failed send removemonitor</li>');                });         });          $("#getall").click(function () {             var uri = queueapi;             //alert(uri);             $.get(uri,                 function (items) {                     data = json.stringify(items);                     $("#getallresults").text(data);                 });                         });          $("#getdetails").click(function () {             var id = $("#queuedetailsid").val();             var uri = queueapi + id;             //alert(uri);             $.get(uri,                 function (items) {                     data = json.stringify(items);                     $('#getdetailsresults').text(data);                 });         });                     $("#getnow").click(function () {             var id = $("#queuenowid").val();             var uri = queueapi + id + "/now";             //alert(uri);             $.get(uri,                 function (items) {                     data = json.stringify(items);                     $('#getnowresults').text(data);                 });         });           $("#startconversationmonitor").click(function () {             var id = $("#queueconversationsid").val();              myhub.server.startqueueconversationmonitor(id)                .done(function () {                    $('#messages').append('<li>client: addmonitor ' + id + '</li>');                })                .fail(function () {                    $('#messages').append('<li>client: failed send addmonitor</li>');                });         });           $("#stopconversationmonitor").click(function () {             var id = $("#queueconversationsid").val();              myhub.server.stopqueueconversationmonitor(id)                .done(function () {                    $('#messages').append('<li>client: removemonitor ' + id + '</li>');                })                .fail(function () {                    $('#messages').append('<li>client: failed send removemonitor</li>');                });         });          $("#getconversations").click(function () {             var id = $("#queueconversationsid").val();             var uri = queueapi + id + "/conversations";             //alert(uri);             $.get(uri,                 function (items) {                     data = json.stringify(items);                     $('#getconversationresults').text(data);                 });         });     });        

here have in c#

using system; using system.collections.generic; using system.linq; using system.text; using system.threading; using system.threading.tasks; using microsoft.aspnet.signalr.client; using microsoft.aspnet.signalr.client.hubs;  namespace consoleapplication3 { class program {     static void main(string[] args)     {         //set connection         var connection = new hubconnection("http://servername/ccmwa/");         connection.tracelevel = tracelevels.all;         connection.tracewriter = console.out;          //make proxy hub based on hub name on server         var myhub = connection.createhubproxy("queuestatistics");          //start connection           connection.start().continuewith(task => {             if (task.isfaulted) {                 console.writeline("there error opening connection:{0}",                                   task.exception.getbaseexception());             } else {                 console.writeline("connected");             }          }).wait();          myhub.invoke<string>("startqueuestatemonitor", "445cb4e7-88a7-47d4-bb13-e8b40854f4a5").continuewith(task =>         {             if (task.isfaulted) {                 console.writeline("there error calling send: {0}",                                   task.exception.getbaseexception());             } else {                 console.writeline("hello");                      console.writeline(task.result);                               }         });           myhub.on("connected", () => console.writeline(" server said connected"));          myhub.on<string>("onqueuenowdataupdate", data => { console.writeline(data); });          //myhub.on<string>("onqueueconversationupdate", data => { console.writeline(data); });           console.read();         connection.stop();     }     } } 

and here output

            08:10:06.4207699 - null - changestate(disconnected, connecting)                               08:10:06.7977915 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - sse: http://servername/ccmwa/signalr/connect?transport=serversentevents&connectiontoken=n6c1mq6e22kyyqralvj2lk2nlwqkqbfzmjols9flk75jhvbwppddp5wgcbmg_9vgextwllqmjetwuat_de8kliodqxzg3zaa6kzhqm9ik4cus0cuwnz8yspn79wpsf3l0&connectiondata=[{"name":"queuestatistics"}]                               08:10:06.8617951 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - changestate(connecting, connected) connected                            08:10:06.8667954 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - sse: onmessage(data: initialized)                              08:10:07.0518060 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - onmessage({"i":"0"}) hello                             08:10:07.1168097 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - sse: onmessage(data: {"c":"gg,0|ix,1|iy,0|iz,0","m":[{"h":"queuestatistics","m":"connected","a":[]}]})  server said connected                 08:10:07.1328106 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - sse: onmessage(data: {"c":"gg,0|ix,1|iy,1|iz,0|hf,13a2","g":"jbb1er_v5dmwm0cxe5lfqluulob69dhmulrh6wm_nm2dbsk-y-qgne7gwpausulsfds1knujuvgu-femd 3iucv56iw545ikdvlxnxl7pmdcgtvzbaijmkijxbedtlsmakxggjzdhr4nd4kwzphmqta2","m":[]})               08:10:07.1338107 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - sse: onmessage(data: {"c":"gg,0|ix,2|iy,1|iz,0|hf,13a2","m":[{"h":"queuestatistics","m":"onqueuenowdataupdate","a":[{"configdata":{"id":"445cb 4e7-88a7-47d4-bb13-e8b40854f4a5","name":"dutch","reporting":"p503","mediatype":0,"mediaserver":null,"mediaserverid":"00000000-0000-0000-0000-000000000000","nowstatisticsurl":null,"statisticshubname":" queuestatistics","links":[],"url":null},"status":"acd","longestwaiting":0.0,"acd":0,"nonacd":0,"out":0,"unavailable":1,"offered":3,"handled":3,"abandoned":0,"interflow":0,"requeue":0,"servicelevel":10 0,"agentsidle":2,"itemswaiting":0,"queueopen":false,"agentsloggedin":0,"agentsavailable":2,"estimatedwaittime":0.0,"averagehandlingtime":0,"detailsurl":null}]}]})                             08:10:07.1878138 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - onerror(newtonsoft.json.jsonreaderexception: error reading string. unexpected token: startobject. path ''.    @ newtonsoft.json.jsonreader.readasstringinternal()    @ newtonsoft.json.linq.jtokenreader.readasstring()    @ newtonsoft.json.serialization.jsonserializerinternalreader.readfortype(jsonreader reader, jsoncontract contract, boolean hasconverter)    @ newtonsoft.json.serialization.jsonserializerinternalreader.deserialize(jsonreader reader, type objecttype, boolean checkadditionalcontent)    @ newtonsoft.json.jsonserializer.deserializeinternal(jsonreader reader, type objecttype)    @ newtonsoft.json.jsonserializer.deserialize(jsonreader reader, type objecttype)    @ newtonsoft.json.linq.jtoken.toobject(type objecttype, jsonserializer jsonserializer)    @ newtonsoft.json.linq.jtoken.toobject[t](jsonserializer jsonserializer)    @ microsoft.aspnet.signalr.client.hubs.hubproxyextensions.convert[t](jtoken obj, jsonserializer serializer)    @ microsoft.aspnet.signalr.client.hubs.hubproxyextensions.<>c__displayclass6`1.<on>b__4(ilist`1 args)    @ microsoft.aspnet.signalr.client.hubs.subscription.onreceived(ilist`1 data)    @ microsoft.aspnet.signalr.client.hubs.hubproxy.invokeevent(string eventname, ilist`1 args)    @ microsoft.aspnet.signalr.client.hubs.hubconnection.onmessagereceived(jtoken message)    @ microsoft.aspnet.signalr.client.connection.microsoft.aspnet.signalr.client.iconnection.onreceived(jtoken message)    @ microsoft.aspnet.signalr.client.transports.transporthelper.processresponse(iconnection connection, string response, boolean& timedout, boolean& disconnected))                            08:10:08.0928655 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - sse: onmessage(data: {"c":"gg,0|ix,2|iy,1|iz,0|hf,13a3","m":[{"h":"queuestatistics","m":"onqueuenowdataupdate","a":[{"configdata":{"id":"445cb 4e7-88a7-47d4-bb13-e8b40854f4a5","name":"dutch","reporting":"p503","mediatype":0,"mediaserver":null,"mediaserverid":"00000000-0000-0000-0000-000000000000","nowstatisticsurl":null,"statisticshubname":" queuestatistics","links":[],"url":null},"status":"acd","longestwaiting":0.0,"acd":0,"nonacd":0,"out":0,"unavailable":1,"offered":3,"handled":3,"abandoned":0,"interflow":0,"requeue":0,"servicelevel":10 0,"agentsidle":2,"itemswaiting":0,"queueopen":false,"agentsloggedin":0,"agentsavailable":2,"estimatedwaittime":0.0,"averagehandlingtime":0,"detailsurl":null}]}]})                             08:10:08.1308677 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - onerror(newtonsoft.json.jsonreaderexception: error reading string. unexpected token: startobject. path ''.    @ newtonsoft.json.jsonreader.readasstringinternal()    @ newtonsoft.json.linq.jtokenreader.readasstring()    @ newtonsoft.json.serialization.jsonserializerinternalreader.readfortype(jsonreader reader, jsoncontract contract, boolean hasconverter)    @ newtonsoft.json.serialization.jsonserializerinternalreader.deserialize(jsonreader reader, type objecttype, boolean checkadditionalcontent)    @ newtonsoft.json.jsonserializer.deserializeinternal(jsonreader reader, type objecttype)    @ newtonsoft.json.jsonserializer.deserialize(jsonreader reader, type objecttype)    @ newtonsoft.json.linq.jtoken.toobject(type objecttype, jsonserializer jsonserializer)    @ newtonsoft.json.linq.jtoken.toobject[t](jsonserializer jsonserializer)    @ microsoft.aspnet.signalr.client.hubs.hubproxyextensions.convert[t](jtoken obj, jsonserializer serializer)    @ microsoft.aspnet.signalr.client.hubs.hubproxyextensions.<>c__displayclass6`1.<on>b__4(ilist`1 args)    @ microsoft.aspnet.signalr.client.hubs.subscription.onreceived(ilist`1 data)    @ microsoft.aspnet.signalr.client.hubs.hubproxy.invokeevent(string eventname, ilist`1 args)    @ microsoft.aspnet.signalr.client.hubs.hubconnection.onmessagereceived(jtoken message)    @ microsoft.aspnet.signalr.client.connection.microsoft.aspnet.signalr.client.iconnection.onreceived(jtoken message)    @ microsoft.aspnet.signalr.client.transports.transporthelper.processresponse(iconnection connection, string response, boolean& timedout, boolean& disconnected))`  

can offer guidance im doing wrong here

not 100% on without running myself but:

i think problem debugging line:

myhub.on<string>("onqueuenowdataupdate", data => { console.writeline(data); }); 

this line treating incoming message string, except data isn't string it's serialized object.

ie what's in data part looks following in trace (with m denoting message body think):

 "m": [             {                 "h": "queuestatistics",                 "m": "onqueuenowdataupdate",                 "a": [                     {                         "configdata": { 

the json deserializer wants

 "m": "foobar" 

really need class declaration matches incoming message (appreciate that's you're going write next).

update class generation:

simplest think generate class json let some-one else you. if paste message (disregard "m:[" part) json2csharp.com:

            {                 "h": "queuestatistics",                 "m": "onqueuenowdataupdate",                 "a": [                     {                         "configdata": {                             "id": "445cb 4e7-88a7-47d4-bb13-e8b40854f4a5",                             "name": "dutch",                             "reporting": "p503",                             "mediatype": 0,                             "mediaserver": null,                             "mediaserverid": "00000000-0000-0000-0000-000000000000",                             "nowstatisticsurl": null,                             "statisticshubname": " queuestatistics",                             "links": [                              ],                             "url": null                         },                         "status": "acd",                         "longestwaiting": 0.0,                         "acd": 0,                         "nonacd": 0,                         "out": 0,                         "unavailable": 1,                         "offered": 3,                         "handled": 3,                         "abandoned": 0,                         "interflow": 0,                         "requeue": 0,                         "servicelevel": 100,                         "agentsidle": 2,                         "itemswaiting": 0,                         "queueopen": false,                         "agentsloggedin": 0,                         "agentsavailable": 2,                         "estimatedwaittime": 0.0,                         "averagehandlingtime": 0,                         "detailsurl": null                     }                 ]             } 

you get:

public class configdata {     public string id { get; set; }     public string name { get; set; }     public string reporting { get; set; }     public int mediatype { get; set; }     public object mediaserver { get; set; }     public string mediaserverid { get; set; }     public object nowstatisticsurl { get; set; }     public string statisticshubname { get; set; }     public list<object> links { get; set; }     public object url { get; set; } }  public class {     public configdata configdata { get; set; }     public string status { get; set; }     public double longestwaiting { get; set; }     public int acd { get; set; }     public int nonacd { get; set; }     public int out { get; set; }     public int unavailable { get; set; }     public int offered { get; set; }     public int handled { get; set; }     public int abandoned { get; set; }     public int interflow { get; set; }     public int requeue { get; set; }     public int servicelevel { get; set; }     public int agentsidle { get; set; }     public int itemswaiting { get; set; }     public bool queueopen { get; set; }     public int agentsloggedin { get; set; }     public int agentsavailable { get; set; }     public double estimatedwaittime { get; set; }     public int averagehandlingtime { get; set; }     public object detailsurl { get; set; } }  public class rootobject {     public string h { get; set; }     public string m { get; set; }     public list<a> { get; set; } } 

you should change name of rootobject makes more sense you. note knows properties in original json, should complex version of message you'll receiving can don't miss out.

then can pick class instance (pretty js version):

myhub.on<rootobject>("onqueuenowdataupdate", data => { <<do rootdata instance here>> }); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -