简体   繁体   English

Xamarin.Forms gRPC 启动 gRPC 调用时出错:连接上的流意外结束

[英]Xamarin.Forms gRPC Error starting gRPC call: unexpected end of stream on Connection

i programming an Application for my study.我为我的学习编写了一个应用程序。

I try to use gRPC in Xamarin.Forms.我尝试在 Xamarin.Forms 中使用 gRPC。

The gRPC is in a seperate Libyry (.NET Standart 2.1). gRPC 位于单独的 Libyry (.NET Standard 2.1) 中。 If i use the code in WPF-Core Project every thing works fine.如果我使用 WPF-Core 项目中的代码,一切正常。

But if I try to use the same in my Xamarin.Forms-Project the Connection don't work.但是,如果我尝试在我的 Xamarin.Forms-Project 中使用相同的连接,则连接不起作用。

if I use the connectionString " http://my.server.com:5050 " I get these Exception如果我使用 connectionString " http://my.server.com:5050 " 我得到这些异常

Error starting gRPC call: unexpected end of stream on Connection{my.server.com:5050, proxy=DIRECT hostAddress=5.189.149.82 cipherSuite=none protocol=http/1.1} (recycle count=0)

if I the SSL Version" https://my.server.com:5050 " I get these Exception如果我使用 SSL 版本“ https://my.server.com:5050 ”,我会收到这些异常

Error starting gRPC call: Connection closed by peer

Here is the Code of the gRPC-Libary这是 gRPC-Libary 的代码

...
        if (connectionString.Contains("http://"))
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

        channel = GrpcChannel.ForAddress(connectionString);
        client = new Haushaltsbuch.HaushaltsbuchClient(channel);

        SuccsessReply reply = new SuccsessReply { Result = false };

        try
        {
            reply = client.Login(new UserRequest
            {
                User = new GRPC_User
                {
                    Username = username,
                    PassHash = passHash
                }
            });
        }
        catch (RpcException e) when (e.Status.Detail.Contains("The SSL connection could not be established"))
        {
            client = null;
            throw new CommunicationException("Fehler mit SSL-Zertifikat des Servers", e);
        }
        catch (RpcException e)
        {
            client = null;
            throw new CommunicationException("Server nicht erreichbar", e);
        }
...

I am only a student and if I google, then it says that Xamarin Forms is supporting gRPC.我只是一个学生,如果我用谷歌搜索,它会说 Xamarin Forms 支持 gRPC。 But why is it not working?但为什么它不起作用?

the .Android Project has the GRPC.Core package from NuGet istalled. .Android 项目安装了来自 NuGet 的 GRPC.Core 包。

Solved it by Replacing通过替换解决它

channel = GrpcChannel.ForAddress(connectionString);

with

        if (connectionString.Contains("http://"))
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            string newConString = connectionString.Replace("http://", "");
            return new Channel(newConString, ChannelCredentials.Insecure);
        }
        else
        {
            string newConString = connectionString.Replace("https://", "");
            return new Channel(newConString, new SslCredentials());
        }

It seems like the GrpcChannel Class isn't working on Andriod.似乎 GrpcChannel 类不适用于 Andriod。

Update: May, 2021更新:2021 年 5 月

Xamarin does not fully support gRPC, so be aware of this when developing your software on Xamarin.Forms. Xamarin 不完全支持 gRPC,因此在 Xamarin.Forms 上开发软件时请注意这一点。

Starting w/ gRPC version 2.34.X, gRPC has started partial support for Xamarin.Forms w/ Android and iOS devices.从 gRPC 版本 2.34.X 开始,gRPC 已开始部分支持带有 Android 和 iOS 设备的 Xamarin.Forms。

Please see this for more information.请参阅了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Xamarin.Forms(iOS 和 Android)调用自签名 gRPC 服务 - How to call self-signed gRPC service from Xamarin.Forms (iOS and Android) Xamarin.Forms 和 gRPC。 “无法连接到所有地址”错误消息 - Xamarin.Forms and gRPC. "failed to connect to all addresses" error message C# gRPC localhost - 启动 gRPC 调用时出错:不知道这样的主机 - C# gRPC localhost - Error starting gRPC call: No such host is known ASP.NET 内核 | gRPC “启动 gRPC 调用时出错:无法建立连接,因为目标机器主动拒绝了它。” - ASP.NET Core | gRPC “Error starting gRPC call: No connection could be made because the target machine actively refused it.” Grpc.Core.RpcException: 'Status (StatusCode = "Unavailable", Detail = "Error starting gRPC call - Grpc.Core.RpcException: 'Status (StatusCode = "Unavailable", Detail = "Error starting gRPC call 在 xamarin.forms (ios) 中启动演示应用程序时出错 - error while starting demo application in xamarin.forms (ios) Xamarin.Forms json 文件流读取器 NullException 错误 - Xamarin.Forms json file stream reader NullException error Xamarin forms 和 gRPC:服务器返回无效或无法识别的响应 - Xamarin forms and gRPC: The server returned an invalid or unrecognized response gRPC 保持 stream 存活 - gRPC Keep stream alive gRPC:如何在 stream gRPC 中找到特定的客户端 - gRPC : How to find a specific client in the stream gRPC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM