Signalr 为什么赢了';t Xamarin表单AspNetCore.signar客户端是否连接到服务器?
我的Xamarin Forms Android应用程序将无法连接到我的Signal服务器 我在IIS中有一个网站,它有一个简单的SignalR聊天中心,我可以通过Javascript客户端、控制台应用程序和WPF应用程序连接到该中心,但这个Xamarin Forms Android应用程序没有连接。Xamarin表单项目添加了Microsoft.AspNetCore.signar.Client v3.1.4包 以下是我如何构建HUB连接:Signalr 为什么赢了';t Xamarin表单AspNetCore.signar客户端是否连接到服务器?,signalr,peer,Signalr,Peer,我的Xamarin Forms Android应用程序将无法连接到我的Signal服务器 我在IIS中有一个网站,它有一个简单的SignalR聊天中心,我可以通过Javascript客户端、控制台应用程序和WPF应用程序连接到该中心,但这个Xamarin Forms Android应用程序没有连接。Xamarin表单项目添加了Microsoft.AspNetCore.signar.Client v3.1.4包 以下是我如何构建HUB连接: hubConnection = new HubConne
hubConnection = new HubConnectionBuilder().WithUrl(@"http://Acme.RealTimeService.com/messages").Build();
违规代码:
await hubConnection.StartAsync();
进攻性错误:
System.IO.IOException:无法从传输连接读取数据:对等方重置连接。
网站上的绑定设置为:
127.0.0.1 Acme.RealTimeService.com
并在C:\Windows\System32\drivers\etc\hosts文件中添加了一个条目:
127.0.0.1 Acme.RealTimeService.com
这是服务器部分中的Startup.cs代码,它是一个以.Net Core 3.1为目标的AspNetCore项目。已将Microsoft.AspNetCore.SignalR v1.1.0软件包添加到项目中
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages(); //Routes for pages
endpoints.MapControllers(); //Routes for my API controllers
endpoints.MapHub<MessageHub>("/messages");
endpoints.MapControllerRoute("default", "{controller=Announcement}/{action=Index}");
});
}
我将url粘贴到浏览器中:
Acme.RealTimeService.com/messages
我得到了这样的回应,我相信这表明了枢纽已经建立起来:
需要连接ID
我将James Montemangno的Xam.Plugin.Connectivity包添加到客户端以检查连接,连接返回为true。我想我可以去IIS
if (CrossConnectivity.Current.IsConnected)
{
try
{
bool connect = await CrossConnectivity.Current.IsRemoteReachable("Acme.RealTimeService.com", 80, 5000);
}
catch (Exception ex)
{
return;
}
}
我尝试了Android项目中的每个TLS设置(Android选项|高级| SSL/TLS实现)。改变设置没有什么不同,我都试过了
我确保Android清单中包含“互联网”所需的权限
我尝试将客户端连接到作为Windows服务托管的普通旧SignalR服务器(不是AspNetCore),但无法连接。在wait hubConnection.StartAsync()上抛出了400个错误请求;调用,这就是为什么我一开始就支持AspNetCore SignalR服务器,认为移动客户端和服务器都需要在AspNetCore上。如果Xamarin表单客户端可以连接到SignalR服务器,我更愿意将其作为Windows服务托管
我不知道下一步该做什么,因为在网上搜寻答案之后,我已经没有什么想法了。除非等待下一版本的AspNetCore.signal发布。IIS绑定实际上是:Type:http IP address:All Unassigned Port:80主机名:Acme.RealTimeService.com。我有一个屏幕截图,但由于我是新手,不允许发布图片,我不得不删除它。我还尝试了HTTPS,这导致StartAsync()调用出现超时异常。
if (CrossConnectivity.Current.IsConnected)
{
try
{
bool connect = await CrossConnectivity.Current.IsRemoteReachable("Acme.RealTimeService.com", 80, 5000);
}
catch (Exception ex)
{
return;
}
}