Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet client 3.0 使用TCP可以调用 golang server 2.0 ? #80

Open
hwfy opened this issue Jan 27, 2021 · 10 comments
Open

dotnet client 3.0 使用TCP可以调用 golang server 2.0 ? #80

hwfy opened this issue Jan 27, 2021 · 10 comments

Comments

@hwfy
Copy link

hwfy commented Jan 27, 2021

您好,

服务端:golang hprose 2.0

客户端:项目.net5.0,hprose 3.0, 我安装的是Hprose.RPC 而不是Hprose.RPC.AspNetCore,我不确定前者是否支持.net5.0

客户端代码:
`
Client cli = new Client("tcp4://192.168.0.1:8000/");
IHello hello = cli.UseService();

string ver = hello.SayHello();
Console.WriteLine(ver);
`

错误堆栈:
System.Threading.ThreadAbortException: System error.
at Hprose.RPC.SocketTransport.<>c__DisplayClass36_0.<<-ctor>b__1>d.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Hprose.RPC.SocketTransport.<>c__DisplayClass36_0.<.ctor>b__1()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) --- End of stack trace from previous location --- at System.Lazy1.CreateValue()
at System.Lazy1.get_Value() at Hprose.RPC.SocketTransport.GetSocket(Uri uri) at Hprose.RPC.SocketTransport.Transport(Stream request, Context context) at Hprose.RPC.Client.Call(String name, Object[] args, Context context) at Hprose.RPC.Client.InvokeAsync[T](String name, Object[] args, ClientContext context) at Hprose.RPC.Client.Invoke[T](String name, Object[] args, ClientContext context) at Hprose.RPC.SyncInvoker1.Invoke(Object[] args)
at Hprose.RPC.InvocationHandler.Invoke(Object proxy, MethodInfo method, Object[] args)
at $Proxy0.IHello.SayHello()

请问怎样才能兼容?还有我无论把tcp的地址修改成0.1 0.10都是以上错误,似乎不能得到地址或访问超时的错误

@andot
Copy link
Member

andot commented Jan 28, 2021

tcp 绑定 2.0 和 3.0 是不兼容的。golang 的 3.0 hprose,这个春节期间会争取完成。

@andot
Copy link
Member

andot commented Jan 28, 2021

2.0 的 tcp 协议的数据没有校验,所以如果有错误数据传输,会导致服务崩溃。3.0 加了一个校验头,所以这就跟 2.0 不兼容了。如果要跟 2.0 的 golang 版本通讯,可以使用 http 协议。Hprose.RPC 里面有 http 客户端和服务器。

@hwfy
Copy link
Author

hwfy commented Jan 28, 2021

那如果降低客户端.net版本呢,不过我通过nuget没有发现2.0的,目前是只能通过HTTP了,辛苦!

@andot
Copy link
Member

andot commented Jan 28, 2021

.net 版本的 1.x 版本是可以跟 golang 2.0 的 tcp 通讯的。但是推荐还是不要用 tcp。没有 http 稳定。

@hwfy
Copy link
Author

hwfy commented Jan 28, 2021

如果用http,它的底层是不是就是个http请求,那和直接调用rest api服务有什么根本区别?

@hwfy
Copy link
Author

hwfy commented Jan 28, 2021

最后一个问题是:如果golang定义的结构方法为:
`

type Hello struct {
SayHello func() (interface{}, error)
}

`
这里就有两个问题,1、它的返回类型有2个,2、它的第一个返回类型为接口,那么在.net中应该如何定义?

@andot
Copy link
Member

andot commented Jan 29, 2021

.NET 中不用管第二个 error 返回值,这个会自动以 Exception 形式返回(并抛出)。

@andot
Copy link
Member

andot commented Jan 29, 2021

interface{} 对应 .NET 中的 object。当然如果你知道具体类型是什么,你可以写具体类型的返回值。

@andot
Copy link
Member

andot commented Jan 29, 2021

你甚至可以定义多个接口方法对应同一个服务器接口,例如:

        public interface IHello {
            object SayHello();
            [Name("SayHello")]
            string SayHelloString();
            [Name("SayHello")]
            int SayHelloInt();
        }

@hwfy
Copy link
Author

hwfy commented Feb 1, 2021

明白,小马哥精通语言太多了,感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants