I have a Web Api Service that sends signalR notifications to a proxy I have running on an MVC website that sits on the same box. After lots of tweaks I have got the web service talking to the hub on the website, confirmed by debug logging.
On the website side, it seems like everything is being called fine and it seems to have a reference to my client browser that is calling the website. Below I'll paste the Hub class and the debug log output to prove this.
The final line is
Clients.Client(conn).addNotification(notification);
which I assume then looks for a JavaScript method matching that signature. Of which I have one. Below is the method in my JS files.
notifyProxy.client.addNotification = function (notification) {
$notificationTableBody.prepend(rowTemplate.supplant(formatNotification(notification)));
};
However setting a break point on this (Using chrome developer tools), the method never gets called. No errors are reported from the MVC website and none in the developer tools console, though I don't know if SignalR writes errors elsewhere.
The only other thing of note is in the JS file I have a line
$.connection.hub.start().done(init);
Which gets called when I set a breakpoint in Chrome developer tools. However the init() method never gets called. Does this mean potentially the hub.start() method is failing? If so how can I find out why?
What is going wrong? I am quite new to signalR so am losing my mind!
Code for my hub class and debug output below
public void PushNotification(EventNotification notification, List<string> users)
{
_logger.WriteDebug("Entered push notification");
if (notification.FriendlyText.Length > 1000)
notification.FriendlyText = notification.FriendlyText.Substring(0, 1000) + "...";
if (users.Contains("*") && users.Count > 1)
{
users.RemoveAll(u => !u.Equals("*"));
}
foreach (var userName in users)
{
_logger.WriteDebug("Push notification for " + userName);
UserConnectionInformation user = null;
if (UserInformation.TryGetValue(userName.ToUpperInvariant(), out user))
{
_logger.WriteDebug("Adding " + notification.FriendlyText + ", " + user.ConnectionIds.Count + " connections");
user.Notifications.Add(notification);
lock (user.ConnectionIds)
{
foreach (var conn in user.ConnectionIds)
{
_logger.WriteDebug("Is Client null - {0}", Clients.Client(conn) == null);
_logger.WriteDebug("Conn {0}", conn);
var proxy = Clients.Client(conn) as ConnectionIdProxy;
_logger.WriteDebug("proxy {0}", proxy.ToString());
Clients.Client(conn).addNotification(notification);
_logger.WriteDebug("Added notification ");
}
}
}
}
}
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Entered push notification
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Push notification for kerslaj1
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Push notification for UK\kerslaj1
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Adding Job 'testrose45job-11dec15121944' ('ROSE-0000045') cancellation has been requested by 'UK\kerslaj1' on 'seflexpool3'., 1 connections
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Is Client null - False
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Conn 3d008947-0d96-4965-bb01-dfd1517c24a5
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - proxy Microsoft.AspNet.SignalR.Hubs.ConnectionIdProxy
11-12-2015 12:19:44,803 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Added notification
See if you can get errors back from the proxy:
$.connection.hub.error(function (error) {
console.log('SignalR error: ' + error)
});
Also you might need to enable client side logging before starting the connection:
// enable client side logging
$.connection.hub.logging = true;
$.connection.hub.start()
.done(function(){ console.log('Now connected, connection ID=' + $.connection.hub.id); })
.fail(function(){ console.log('Could not Connect!'); });
});
Let's see if we get any further from there and if the start of the hub connection is the actual problem.
Related
We have a web application with .NET 5 MVC, in which after authentication process we Open the signalR connection.
When we load the same page by duplicate the browser instance, the rest of the user get struct and application stops responding. Also other users are also not able use application.
While viewing currently processing request in IIS -> Worker process it shows all pending connection request with high time elapsed for the open browser instances.
once we close the browser tab, application starts working for other user.
Kindly suggest the solution for the same.
find the below mention code
var startConnection = function () {
var signalRConnId = '';
if (sr_connection == null && spGeneral.useSignalR) {
sr_connection = new signalR.HubConnectionBuilder().withUrl("/SignalRHub").withAutomaticReconnect().build();
return sr_connection.start().then(function () {
signalRConnId = sr_connection.connection.connectionId;
console.log('Signal R Connection Id : ' + signalRConnId);
console.log('Signal R Started');
return sr_connection;
}).catch(function (err) {
console.error('Signal R Notification Error: ' + err.toString());
});
}
else {
return sr_connection
}
}
Server code
public Task SendNotificationAsync(string subcriber,object data)
{
return _hub.Clients.All.SendAsync(subcriber, data);
}
It was a problem of windows 10 with IIS 10. We shifted our web app deployment to windows server 2016. So it got resolved.
It seems a problem with Window 10.
I've built a small App that register a service that looks like an Airpint to IOS device.
I have little knowledge on IPP programming.
I am using Monozeroconf Dll and C# to register my service etc... and that's all work fine but i would like to display a popup to enter Username and password so that i can identify the person that is printing.
Can someone help or point me to the right direction.
Thanks in advance.
Just in case someone out there has been struggling with this, here's my code
if (!HttpListener.IsSupported)
{
Console.WriteLine("Server does not support Http Listener.");
return;
}
// URI prefixes required,
if (prefixes == null || prefixes.Length == 0)
throw new ArgumentException("prefixes required");
// Create a listener.
HttpListener listener = new HttpListener();
// Add the prefixes.
foreach (string s in prefixes)
{
listener.Prefixes.Add(s);
}
listener.Start();
listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
Console.WriteLine("About to listen to " + prefixes[0].ToString());
if (listener.IsListening) {
Console.WriteLine("Currently Listening to " + prefixes[0].ToString());
}
//Wait until a connection is made before continuing
//allDone.WaitOne();
// Note: The GetContext method blocks while waiting for a request.
HttpListenerContext context = listener.GetContext();
//Retrives Username and password from the Http Request
var hlbi = (HttpListenerBasicIdentity)context.User.Identity;
Console.WriteLine("Username: " + hlbi.Name);
Console.WriteLine("Password: " + hlbi.Password);
listener.Stop();`
for some reason my firewall was blocking connection on Getcontext(), so i had to put an excpetion on the IPP port 631.(not the application)
I have the following code in my Program.cs to start a self-hosted nancy app on Mono 4.2.2.
public static void Main (string[] args)
{
var uri = "";
if(ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Production || ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Staging)
{
uri = string.Format("http://localhost:{0}", Environment.GetEnvironmentVariable("PORT").ToString());
}
else if(ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Development)
{
uri = string.Format("http://localhost:8888");
}
Console.WriteLine("Starting Reflect.Web application on " + uri);
// initialize an instance of NancyHost
var host = new NancyHost(new Uri(uri));
host.Start(); // start hosting
// check if we're running on mono
if (Type.GetType("Mono.Runtime") != null)
{
// on mono, processes will usually run as daemons - this allows you to listen
// for termination signals (ctrl+c, shutdown, etc) and finalize correctly
UnixSignal.WaitAny(new[] {
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGTERM),
new UnixSignal(Signum.SIGQUIT),
new UnixSignal(Signum.SIGHUP)
});
}
else
{
Console.ReadLine();
}
host.Stop(); // stop hosting
}
This code ran fine for months. Just now this error started showing up:
System.Net.Sockets.SocketException: Could not resolve host '+'
on this line:
host.Start(); // start hosting
I am not aware of any updates I have made recently to any dependency.
Has anyone ever come across this before? And why the '+' sign?
+ can be part of the "URI prefix string" that .NET's HttpListener (not sure about mono) uses to determine where it should host the application, check out the HttpListener's Class remarks for more information:
Similarly, to specify that the HttpListener accepts all requests sent to a port, replace the host element with the "+" character, "https://+:8080". The "*" and "+" characters can be present in prefixes that include paths.
My guess is that your code is checking ReflectConfiguration.CurrentEnviroment and missing the cases you're selecting for.
Is there not an environment configured/present? or are you not in Production, Staging, or Development? What is the value of uri when you create a new URI object?
We are using Azure Service Bus in our project and while reading messages from service bus topic/subscription.
We are using subscriptionClient.OnMessageAsync event in conjunction with onMessageOptions.ExceptionReceived.
Let me write down the steps we followed to reproduce the issue we are facing.
Create a service bus namespace with default config in the azure portal
Create a topic inside it with default config in the azure portal
Create a subscription inside it with default config in the azure portal
Create a console app and paste the code added below
Connect the service bus using Service Bus Explorer
Run the console app
Send a few test messages from service bus explorer & watch the console app window
Though the messages are processed successfully every time the control is going inside the ExceptionReceived method
Here's the code:
class Program
{
static void Main()
{
var subscriptionClient = SubscriptionClient.CreateFromConnectionString
(
"servicebusendpointaddress",
"topicname",
"subscriptionname",
ReceiveMode.PeekLock
);
var onMessageOptions = new OnMessageOptions();
onMessageOptions.ExceptionReceived += OnMessageError;
subscriptionClient.OnMessageAsync(OnMessageReceived, onMessageOptions);
Console.ReadKey();
}
private static void OnMessageError(object sender, ExceptionReceivedEventArgs e)
{
if (e != null && e.Exception != null)
{
Console.WriteLine("Hey, there's an error!" + e.Exception.Message + "\r\n\r\n");
}
}
private static async Task OnMessageReceived(BrokeredMessage arg)
{
await arg.CompleteAsync();
Console.WriteLine("Message processing done!");
}
}
Are we missing something here?
Also one point to mention is that is we enable ‘autocomplete’ and remove the await arg.CompleteAsync(); then this is not happening.
var onMessageOptions = new OnMessageOptions() { AutoComplete = true};
In both the cases the messages are being processed successfully & removed from the subscription immediately.
You might be getting this because you are debugging and stepping though the code i.e. the lock expires. The LockDuration by default is 60 seconds.
You can try setting your OnMessageOptions() like this to test:
var onMessageOptions = new OnMessageOptions() { AutoRenewTimeout = TimeSpan.FromMinutes(1) };
I have Windows Service developed in C#
I have Windows Server 2012 with 2 private queues: queueRequests and queueResponses.
My queues are not transactional.
I have Client that execute Console Application with credentials MyDomain\UserDeploy .
Windows Service in Server is executed with credentials MyDomain\UserAgent.
MyDomain\UserAgent and MyDomain\UserDeploy user has Full control about queues: queueRequests and queueResponses.
Server and Client are in the same MyDomain.
Console Application Client to send message and read message from/to private queue in Server.
Windows Service in Server to send message and read message from/toprivate queue.
Execution Steps:
Console Application Client send Message A to private Queue
queuerequests in Server
Windows Service read Message A from private queue queuerequests
Windows Service sendMessage B to private queue queueresponses
Console Application Client read Message B from private queue
queueresponses.
It was working all steps.
Now, I don't know the reason, the step 4 fails. Client Not reads message from remote queue.
I don't understand why: Client can send message to queue, but not reads from queue.
I get a MessageQueueException but exception.Message is empty.
Any suggestions for get good troubleshooting ?
Fragment code:
const string ForSend = #"FormatName:DIRECT=OS:{0}\private$\DeploymentCommands";
const string ForRead = #"FormatName:DIRECT=OS:{0}\private$\DeploymentResponses";
private DeploymentResponse WaitForResponse()
{
try
{
Message rsp = colaStatus.ReceiveByCorrelationId(correlationId, new TimeSpan(0, timeOut, 0));
DeploymentResponse ret = rsp.Body as DeploymentResponse;
Console.WriteLine("Respuesta WaitForResponse:" + ret.DeploymentId + " - " + ret.Status);
Trace.WriteLine("Respuesta WaitForResponse:" + ret.DeploymentId + " - " + ret.Status);
return ret;
}
catch (MessageQueueException ex)
{
Console.WriteLine("Error WaitForResponse in remote server " + remoteServer + ". " + ex.Message);
Trace.WriteLine("Error WaitForResponse in remote server " + remoteServer + ". " + ex.Message);
return null;
}
catch (Exception)
{
throw;
}
}
More about MessageQueueException .
I get
Message: null
MessageQueueErrorCode -2147023169
ErrorCode -2147467259
but not found that code in MessageQueueErrorCode Enumeration.
-2147023169 value. In Hex: 800706BF
-2147467259 value. In Hex: 80004005
Not much info about those codes. Only I get:
0x80004005 -2147467259 E_Fail
0x800706BF -2147023169 PRC_S_Call_Failed_DNE
Windows Update Codes
Full trace exception:
Message: - MessageQueueErrorCode -2147023169 - ErrorCode-2147467259
StackTrace:
at System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
at System.Messaging.MessageQueue.ReceiveBy(String id, TimeSpan timeout,
Boolean remove, Boolean compareId, Boolean throwTimeout,
MessageQueueTransaction transaction, MessageQueueTransactionType
transactionType)
at System.Messaging.MessageQueue.ReceiveByCorrelationId(String
correlationId, TimeSpan timeout)
at DeploymentAgent.Client.DeploymentInvoker.WaitForResponse()
Things you might try:
Changing queue permissions - see here, try setting permission to "Everyone" (for the test only).
Try setting AllowNonauthenticatedRPC in registry - details here
May you should consider to use public instead of private queues. Read the following articles of the advantages of public queues:
Destination Queues
Public and private queues