- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我尝试连接到 c# 中的服务,我无法控制该服务并且无法更改那里的任何内容,而且我也没有任何文档可以帮助:(
所以我想做的是将这个 JavaScript SignalR 客户端更改为 .net(但不是全部)
$(document).ready(function () {
//URL of the 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 we are Connected</li>');
};
//Wire event handlers
myHub.client.reconnected = function () {
$('#messages').append('<li>Server: Says we are Reconnected</li>');
};
//Start
$.connection.hub.start()
.done(function () {
logMessage("Client: Connection Started");
//myHub.server.joinFoo()
// .done(function () {
// logMessage("Client: Sent Join to Server");
// })
})
.fail(function () {
logMessage("Client: Could not connect to server");
});
$("#startNow").click(function () {
var id = $("#queueNowId").val();
myHub.server.startQueueStateMonitor(id)
.done(function () {
$('#messages').append('<li>Client: addMonitor for ' + id + '</li>');
})
.fail(function () {
$('#messages').append('<li>Client: failed to 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 for ' + id + '</li>');
})
.fail(function () {
$('#messages').append('<li>Client: failed to 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 for ' + id + '</li>');
})
.fail(function () {
$('#messages').append('<li>Client: failed to send addMonitor</li>');
});
});
$("#stopConversationMonitor").click(function () {
var id = $("#queueConversationsId").val();
myHub.server.stopQueueConversationMonitor(id)
.done(function () {
$('#messages').append('<li>Client: removeMonitor for ' + id + '</li>');
})
.fail(function () {
$('#messages').append('<li>Client: failed to 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);
});
});
});
这是我目前在 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 to hub based on hub name on server
var myHub = connection.CreateHubProxy("queueStatistics");
//Start connection
connection.Start().ContinueWith(task => {
if (task.IsFaulted) {
Console.WriteLine("There was an error opening the 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 was an 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();
}
}
}
这是它的输出
08:10:06.4207699 - null - ChangeState(Disconnected, Connecting)
08:10:06.7977915 - 66fd7caa-b3f8-4297-9c83-5a2dd5c9e72e - SSE: GET 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 ''. at Newtonsoft.Json.JsonReader.ReadAsStringInternal() at Newtonsoft.Json.Linq.JTokenReader.ReadAsString() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer) at Microsoft.AspNet.SignalR.Client.Hubs.HubProxyExtensions.Convert[T](JToken obj, JsonSerializer serializer) at Microsoft.AspNet.SignalR.Client.Hubs.HubProxyExtensions.<>c__DisplayClass6`1.<On>b__4(IList`1 args) at Microsoft.AspNet.SignalR.Client.Hubs.Subscription.OnReceived(IList`1 data) at Microsoft.AspNet.SignalR.Client.Hubs.HubProxy.InvokeEvent(String eventName, IList`1 args) at Microsoft.AspNet.SignalR.Client.Hubs.HubConnection.OnMessageReceived(JToken message) at Microsoft.AspNet.SignalR.Client.Connection.Microsoft.AspNet.SignalR.Client.IConnection.OnReceived(JToken message) at 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 ''. at Newtonsoft.Json.JsonReader.ReadAsStringInternal() at Newtonsoft.Json.Linq.JTokenReader.ReadAsString() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer) at Microsoft.AspNet.SignalR.Client.Hubs.HubProxyExtensions.Convert[T](JToken obj, JsonSerializer serializer) at Microsoft.AspNet.SignalR.Client.Hubs.HubProxyExtensions.<>c__DisplayClass6`1.<On>b__4(IList`1 args) at Microsoft.AspNet.SignalR.Client.Hubs.Subscription.OnReceived(IList`1 data) at Microsoft.AspNet.SignalR.Client.Hubs.HubProxy.InvokeEvent(String eventName, IList`1 args) at Microsoft.AspNet.SignalR.Client.Hubs.HubConnection.OnMessageReceived(JToken message) at Microsoft.AspNet.SignalR.Client.Connection.Microsoft.AspNet.SignalR.Client.IConnection.OnReceived(JToken message) at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.ProcessResponse(IConnection connection, String response, Boolean& timedOut, Boolean& disconnected))`
任何人都可以对我在这里做错的事情提供任何指导
最佳答案
如果没有自己运行它,不是 100%,但是:
我认为问题是你的调试线:
myHub.On<string>("onQueueNowDataUpdate", data => { Console.WriteLine(data); });
此行将传入消息视为字符串,除了数据不是字符串,因为它是序列化对象。
即数据中的内容是跟踪中如下所示的部分(我认为 M 表示消息正文):
"M": [
{
"H": "queueStatistics",
"M": "onQueueNowDataUpdate",
"A": [
{
"configData": {
Json 反序列化器想要类似的东西
"M": "Foobar"
您确实需要一个与传入消息相匹配的类声明(请注意,这可能是您接下来要编写的内容)。
类生成更新:
从 Json 生成类的最简单的想法是让其他人为您做。如果您将消息(忽略 "M:["
部分)粘贴到 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
}
]
}
你得到:
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 A
{
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> A { get; set; }
}
您应该将 RootObject
的名称更改为对您来说更有意义的名称。另请注意,显然这只知道原始 Json 中的属性,因此您应该使用您将收到的消息的最复杂版本来执行此操作,这样您就不会错过任何内容。
然后您可以使用(与使用 JS 版本非常相似)获取类实例:
myHub.On<RootObject>("onQueueNowDataUpdate", data => { <<Do something with RootData instance here>> });
关于c# - Signalr .net 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30933327/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!