C# Signalr - An error occured while sending the request - c#

So I'm trying out SignalR, for this project I'm doing. And I don't really understand the .WithUrl paramater in HubConnectionBuilder. How do I know which URL to specify, if I want to host on localhost?
My HUB:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
namespace SignalRChat.MyHub
{
public class MyHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("SendMessage", user, message);
}
}
}
My program.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.SignalR.Client;
using Owin;
using SignalRChat.MyHub;
using Microsoft.Owin.Hosting;
using Microsoft.Owin.Cors;
namespace SignalRChat
{
public partial class Form1 : Form
{
HubConnection connection;
public Form1()
{
InitializeComponent();
connection = new HubConnectionBuilder()
.WithUrl("http://localhost:8080/MyHub")
.Build();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private async void button1_Click(object sender, EventArgs e)
{
try
{
await connection.StartAsync();
//await connection.InvokeAsync("SendMessage", textBox1.Text, textBox2.Text);
//listBox1.Items.Add($"{textBox1.Text}: {textBox2.Text}");
}
catch (Exception ex)
{
listBox1.Items.Add(ex.Message);
}
}
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I'm getting the following error:
Error message/Exception
I've tried searching around the internet, about how to use the .WithUrl, but with no luck. I'm hoping that some of you guys can help a brother out!

Can you try displaying the innerException in your exception handler and see what the detailed error is?
Also, check your SignalR Event Hub (http://localhost:8080/MyHub) is running.
If your SignalR event hub is running then try debugging it and see if it receiving requests in your service hub background task.
Another thing you can check is the URL you are calling is identical to the SignalR hub route configured in your SignalR hub hub service:
routes.MapHub<MyHubClass>("/MyHub");

Related

C# client SocketIoClientDotNet.Client is not work(node server)

C# WinForms client:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Quobject.SocketIoClientDotNet.Client;
namespace socket_TEST
{
#nullable enable
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
connect();
}
public void connect()
{
var socket = IO.Socket("http://127.0.0.1:3000/");
socket.On(Socket.EVENT_CONNECT, () =>
{
MessageBox.Show("connection!");
});
socket.On("connection", () =>
{
MessageBox.Show("connection!");
});
}
}
}
Nodejs server:
const app=require('express')();
const server=require('http').Server(app);
const io=require('socket.io')(server);
io.sockets.on("connection",function(socket){
console.log("new client");
});
server.listen(3000,function(){
console.log("------SERVER RUNNING------");
});
I want to connect C# and Nodejs servers.
But the connection is still not working. Can you tell me why and how should I solve it?
i see SocketIoClientDotNet THIS PROJECT IS DEPRECATED

Issue with using OpenSlide

I am new to C# and can't get OpenSlide to work. I need it to be able to read SVS files. Below is the code I have used. Is it possible I am missing something in a directory? My boss has used the same code and can get it to run without issue.
I am getting the following error:
OpenSlideNET.OpenSlideUnsupportedFormatException: 'Exception of type 'OpenSlideNET.OpenSlideUnsupportedFormatException' was thrown.'
using OpenSlideNET;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SVSCurrent1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenSlideImage image = OpenSlideImage.Open("‪C:\\projects\\SVS\\JP2K-33003-1.svs");
}
}
}

'ServiceController' does not contain a definition for 'GetServices'

I what to list all services on my computer with a C# form APP.
But when i follow what all answers to list all services say i get:
'ServiceController' does not contain a definition for 'GetServices'
All my research leads to:
using ServiceStack.Host;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace myFromApp
{
public partial class Services : Form
{
public Services()
{
InitializeComponent();
}
private void RefreshServiceBbutton_Click(object sender, EventArgs e)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController scTemp in scServices)
{
if (scTemp.Status == ServiceControllerStatus.Running)
{
//do stuff with each service(display info and such)
}
}
}
}
}
`
you have to import the namespace System.ServiceProcess and then you can call ServiceController[] services = ServiceController.GetServices(); to obtain the list of services.

Connecting VLC Plugin

I want to make stream application for RTSP cam to open VLC
when I press the button show to me the stream in the application but it doesn't show to me anything I want the program to display the stream in VLC
this the code of the application using c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace vlc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void axVLCPlugin21_Enter(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
axVLCPlugin21.playlist.add("rtsp://192.168.0.209:554/mpeg4", "live", "network-caching=75");
//pictureBox1.Visible = false;
axVLCPlugin21.playlist.play();
}
}
}

tweetinvi always returns null

I have been trying to get tweetinvi to work and it always returns null for whatever I do. I have tried 3 of the queries with search, rate limit and logged in user and all return null. Dont know what i've done wrong :s first time I have tried to use twitter api
Form1
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Tweetinvi;
using Tweetinvi.Core.Enum;
using Tweetinvi.Core.Extensions;
using Tweetinvi.Core.Interfaces;
using Tweetinvi.Core.Interfaces.Controllers;
using Tweetinvi.Core.Interfaces.DTO;
using Tweetinvi.Core.Interfaces.DTO.QueryDTO;
using Tweetinvi.Core.Interfaces.Models;
using Tweetinvi.Core.Interfaces.Models.Parameters;
using Tweetinvi.Core.Interfaces.oAuth;
using Tweetinvi.Core.Interfaces.Streaminvi;
using Tweetinvi.Json;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// TwitterCredentials.SetCredentials("xx", "xx", "xx", "xx");
}
public void Search_SimpleTweetSearch()
{
// IF YOU DO NOT RECEIVE ANY TWEET, CHANGE THE PARAMETERS!
var tweets = Search.SearchTweets("hi");
foreach (var tweet in tweets)
{
// Console.WriteLine("{0}", tweet.Text);
textBox1.Text += "tweet.Text" + System.Environment.NewLine;
}
}
public void test()
{
var user = User.GetLoggedUser();
textBox1.Text += user.ScreenName + System.Environment.NewLine;
}
private void button1_Click(object sender, EventArgs e)
{
test();
// Search_SimpleTweetSearch();
}
private void button2_Click(object sender, EventArgs e)
{
var rateLimits = RateLimit.GetCurrentCredentialsRateLimits();
textBox1.Text += rateLimits.ToString() + System.Environment.NewLine;
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Tweetinvi;
using Tweetinvi.Core.Enum;
using Tweetinvi.Core.Extensions;
using Tweetinvi.Core.Interfaces;
using Tweetinvi.Core.Interfaces.Controllers;
using Tweetinvi.Core.Interfaces.DTO;
using Tweetinvi.Core.Interfaces.DTO.QueryDTO;
using Tweetinvi.Core.Interfaces.Models;
using Tweetinvi.Core.Interfaces.Models.Parameters;
using Tweetinvi.Core.Interfaces.oAuth;
using Tweetinvi.Core.Interfaces.Streaminvi;
using Tweetinvi.Json;
namespace WindowsFormsApplication4
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
TwitterCredentials.SetCredentials("xx", "xx", "xx", "xx");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
You can get more information on what has gone wrong using the ExceptionHandler. The library aims not to throw exceptions, rather it returns null and adds information on errors to the ExceptionHandler class which is in the Tweetinvi namespace. So, try checking for null on the returned object, then look at the ExceptionHandler... something like this:
if (tweets == null)
{
textBox1.Text += ExceptionHandler.GetLastException().TwitterDescription;
}
The most likely culprit is that you're not actually authenticated.

Categories

Resources