部署应用程序时SignalR出错 [英] SignalR Error when I deploy application
问题描述
嘿伙计们我有一个问题,我需要一些帮助。我有一个SignalR Web项目,我通过控制台应用程序进行通信。当我在本地运行我的SignalR Web应用程序时它工作正常没有任何问题,但是当我将它部署到IIS并尝试创建集线器代理时,我得到下面的错误,我一直在拉我的头发整天,我找不到解决方案。任何帮助都非常苛刻。
错误:
解析值时遇到意外的字符:<路径'',第3行,第1位。}
控制台应用程序:
< pre lang =c#> var connection = new HubConnection(txtSignalRWebsite.Text);
// 根据服务器上的集线器名称设置集线器代理
var myHub = connection.CreateHubProxy( dbHub );
// 开始连接
connection.Start()。 ContinueWith(task = >
{
if (task.IsFaulted)
{
Console.WriteLine( 错误 + task.Exception.ToString( ));
}
else
{
myHub.Invoke( DisplayHello);
}
})。Wait();
Stack Trace
(内部异常#0 )Newtonsoft.Json.JsonReaderException:遇到意外的字符,而解析 value :< 跨度>。路径' ',行 3 ,位置 1 。
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.ReadInternal()
at Newtonsoft.Json.JsonTextReader.Read()
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.JsonConvert.DeserializeObject( String value ,类型类型,JsonSerializerSettings设置)
at Newtonsoft.Json.JsonConvert.DeserializeObject [T]( St ring value ,JsonSerializerSettings设置)
at Newtonsoft.Json.JsonConvert.DeserializeObject [T](字符串 值)
at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper。< GetNegotiationResponse> b__0(IResponse response)
.Microsoft.AspNet.SignalR.TaskAsyncHelper。<> c__DisplayClass23`2。< Then> b__21(任务`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2。<> c__DisplayClass48。< RunTask> b__47(任务`1 t)< ---
生成的集线器Js文件
/ * !
* ASP.NET SignalR JavaScript库v1.1.0
* http://signalr.net/
*
*版权所有Microsoft Open Technologies,Inc。保留所有权利。
*根据Apache 2.0许可b $ b * https://github.com/SignalR/SignalR/blob/master/LICENSE.md
*
* /
// /< reference path =.. \..\SignalR。 Client.JS\Scripts\jquery-1.6.4.js/>
// /< reference path =jquery.signalR.js/>
( function ($, window ){
// /< param name = $type =jQuery/>
use strict ;
if ( typeof ($ .signalR)!== function){
throw new 错误( SignalR:未加载SignalR。请确保在〜/ signalr / hubs之前引用jquery.signalR-x.js。);
}
var signalR = $ .signalR;
function makeProxyCallback(hub,callback){
return function (){
// 调用客户端集线器方法
callback.apply(hub,$ .makeArray(arguments));
};
}
function registerHubProxies(instance,shouldSubscribe){
var key,hub,memberKey,memberValue ,subscriptionMethod;
for ( in instance){
if (instance.hasOwnProperty(key)){
hub =实例[键]。
if (!(hub.hubName)){
// 不是客户中心
继续;
}
if (shouldSubscribe){
// 我们要订阅集线器事件
subscriptionMethod = hub.on;
}
其他 {
// 我们想取消订阅中心事件
subscriptionMethod = hub.off;
}
// 遍历集线器上的所有成员并查找客户端集线器函数订阅/取消订阅
for (memberKey in hub.client){
if (hub.client.hasOwnProperty(memberKey)){
memberValue = hub.client [memberKey];
if (!$。isFunction(memberValue)){
// 不是客户端集线器功能
继续;
}
subscriptionMethod.call(hub,memberKey,makeProxyCallback(hub,memberValue));
}
}
}
}
}
$ .hubConnection.prototype.createHubProxies = function (){
var proxies = {};
此 .starting( function (){
// 将订阅代理注册为订阅
// (instance,shouldSubscribe)
registerHubProxies(proxies, true );
this ._ registerSubscribedHubs();
})。disconnected( function (){
// 当我们断开连接时取消订阅所有集线器代理。这是为了确保我们不重新添加函数回调。
// (instance,shouldSubscribe)
registerHubProxies(proxies, false < /跨度>);
});
proxies.clientNotificationHub = this .createHubProxy(' clientNotificationHub'跨度>);
proxies.clientNotificationHub.client = {};
proxies.clientNotificationHub.server = {
checkForPasswordExpiry: function (iUserId,iConnectionId){
return proxies.clientNotificationHub.invoke.apply(proxies.clientNotificationHub,$ .merge([ CheckForPasswordExpiry ],$ .makeArray(arguments)));
}
};
proxies.dbHub = this .createHubProxy(' dbHub'跨度>);
proxies.dbHub.client = {};
proxies.dbHub.server = {
displayHello: function (){
return proxies.dbHub.invoke.apply(proxies.dbHub,$ .merge([ DisplayHello],$ .makeArray(arguments)));
},
processMessage: function (_lstNotificationJSON,sUserName){
return proxies.dbHub.invoke.apply(proxies.dbHub,$ .merge([ ProcessMessage ],$ .makeArray(arguments)));
},
setConnection: function (iUserId){
return proxies.dbHub.invoke.apply(proxies.dbHub,$ .merge([ SetConnection],$ .makeArray(arguments)));
},
updateClientNotification: function (iClientNotificationId,eEventType,csNotification,iUserId){
return proxies.dbHub.invoke.apply(proxies.dbHub,$ .merge([ UpdateClientNotification],$ .makeArray(arguments)));
},
updateClientNotificationProcessed: function (iClientNotificationId){
return proxies.dbHub.invoke.apply(proxies.dbHub,$ .merge([ UpdateClientNotificationProcessed],$ .makeArray(arguments)));
}
};
返回代理;
};
signalR.hub = $ .hubConnection( / i-conX_10_2_SignalR / signalr,{useDefaultPath: false });
$ .extend(signalR,signalR.hub.createHubProxies());
}( window .jQuery, window ));
, window ){
// /< param name =
type =jQuery/>
use strict;
if ( typeof (
.signalR)!== function){
throw new 错误( SignalR:SignalR未加载。请确保在〜/ signalr / hubs之前引用jquery.signalR-x.js。);
}
var signalR =
Hey guys I have a problem which I need a little help with. I have a SignalR web project which I communicate with through a console application. When I run my SignalR Web application locally it works fine without any issues but when I deploy it to IIS and try create the hub proxy I get the error below, I have been pulling my hair out all day and I can't find a solution. Any help is very much apreciated.
Error:
"Unexpected character encountered while parsing value: <. Path '', line 3, position 1."}
Console application:
var connection = new HubConnection(txtSignalRWebsite.Text);
//Make proxy to hub based on hub name on server
var myHub = connection.CreateHubProxy("dbHub");
//Start connection
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
Console.WriteLine("Error" + task.Exception.ToString());
}
else
{
myHub.Invoke("DisplayHello");
}
}).Wait();
Stack Trace
(Inner Exception #0) Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 3, position 1.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.ReadInternal()
at Newtonsoft.Json.JsonTextReader.Read()
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.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.<GetNegotiationResponse>b__0(IResponse response)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass23`2.<Then>b__21(Task`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass48.<RunTask>b__47(Task`1 t)<---
Generated Hubs Js file
/*!
* ASP.NET SignalR JavaScript Library v1.1.0
* http://signalr.net/
*
* Copyright Microsoft Open Technologies, Inc. All rights reserved.
* Licensed under the Apache 2.0
* https://github.com/SignalR/SignalR/blob/master/LICENSE.md
*
*/
/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window) {
/// <param name="$" type="jQuery" />
"use strict";
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/hubs.");
}
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!(hub.hubName)) {
// Not a client hub
continue;
}
if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
}
else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}
// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function () {
var proxies = {};
this.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(proxies, false);
});
proxies.clientNotificationHub = this.createHubProxy('clientNotificationHub');
proxies.clientNotificationHub.client = { };
proxies.clientNotificationHub.server = {
checkForPasswordExpiry: function (iUserId, iConnectionId) {
return proxies.clientNotificationHub.invoke.apply(proxies.clientNotificationHub, $.merge(["CheckForPasswordExpiry"], $.makeArray(arguments)));
}
};
proxies.dbHub = this.createHubProxy('dbHub');
proxies.dbHub.client = { };
proxies.dbHub.server = {
displayHello: function () {
return proxies.dbHub.invoke.apply(proxies.dbHub, $.merge(["DisplayHello"], $.makeArray(arguments)));
},
processMessage: function (_lstNotificationJSON, sUserName) {
return proxies.dbHub.invoke.apply(proxies.dbHub, $.merge(["ProcessMessage"], $.makeArray(arguments)));
},
setConnection: function (iUserId) {
return proxies.dbHub.invoke.apply(proxies.dbHub, $.merge(["SetConnection"], $.makeArray(arguments)));
},
updateClientNotification: function (iClientNotificationId, eEventType, csNotification, iUserId) {
return proxies.dbHub.invoke.apply(proxies.dbHub, $.merge(["UpdateClientNotification"], $.makeArray(arguments)));
},
updateClientNotificationProcessed: function (iClientNotificationId) {
return proxies.dbHub.invoke.apply(proxies.dbHub, $.merge(["UpdateClientNotificationProcessed"], $.makeArray(arguments)));
}
};
return proxies;
};
signalR.hub = $.hubConnection("/i-conX_10_2_SignalR/signalr", { useDefaultPath: false });
$.extend(signalR, signalR.hub.createHubProxies());
}(window.jQuery, window));
, window) { /// <param name="
" type="jQuery" /> "use strict"; if (typeof (
.signalR) !== "function") { throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/hubs."); } var signalR =
这篇关于部署应用程序时SignalR出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!