ASP.NET

推荐列表 站点导航

当前位置:首页 > 脚本编程 > ASP.NET >

Thrift实现C#调用Java开发步骤详解

来源:网络整理  作者:网友投稿  发布时间:2020-12-29 10:16
转载请注明出处:jiqbull;钦 39;stechnicalBlogApacheThrift是Facebook实现的一种高效的、支持多种IT之家语言的远程服务调用的框...

安装步骤这里就不赘述了, 8899);TProtocolprotocol = new TBinaryProtocol(transport);test.Hello.Client client = newtest.Hello.Client(protocol);transport.Open();Console.WriteLine(Client calls client.helloString().....);Console.WriteLine(client.helloString(jiyiqin));client.Dispose();}}} 7 运行 运行java服务端Server.java: thrift server init thrift server start thrift server host on port 8899 get jiyiqin 1 运行C#客户端代码ClientTest.cs Client calls client.helloString()..... Hello jiyiqin 1 请按任意键继续 可以看到Thrift和ICE等跨语言RPC框架开发步骤非常相似。

1 下载Thrift 下载地址: thrift-0.9.3.exe 用于编译Thrift中间文件生成对应语言代码的工具 thrift-0.9.3.tar.gz 包含Thrift各个语言的源码库,需要安装Ant。

true);Args args = newArgs(serverTransport);args.processor(process);args.protocolFactory(portFactory);TServer server = newTThreadPoolServer(args);server.serve();} catch (TTransportException e) {e.printStackTrace();}}publicstaticvoidmain(String[] args) {System.out.println(thrift server init);Server server = new Server();System.out.println(thrift server start);server.startServer();System.out.println(thrift server end);} } 6 编写C#客户端代码 新建普通控制台项目,几乎相同, (1)首先编写接口实现类: package test;import org.apache.thrift.TException;import test.Hello.Iface; public classHelloImpl implementsIface{privatestaticintcount= 0;@OverridepublicString helloString(String word)throwsTException {count += 1;System.out.println(get + word + +count);return hello + word + + count;} } (2)编写寄宿代码, , 5 编写Java服务端代码 新建普通Java项目,但是和基于Servlet的Hessian这种跨语言RPC框架差别较大, 打开命令行CD到java库代码所在的路径:E:Thrift hrift-0.9.3libjava(包含build.xml) 然后直接执行ant命令即可发现build目录下生成对应的jar文件,启动并监听在指定端口: package test;import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol.Factory; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.server.TThreadPoolServer.Args; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TTransportException; import test.Hello.Processor; public classServer {@SuppressWarnings({rawtypes。

类似的跨语言RPC框架还有ICE、Hessian、Protocol Buffer、Avro等,注意包名, 3 编写thrift中间文件namespace java testnamespace csharp testservice Hello {string helloString(1:string word)}4 生成Java和C#各自的接口文件 Thrift-0.9.3.exe gen java test.thrift Thrift-0.9.3.exe gen csharp test.thrift 可以看到在当前目录下会出现生成的对应代码。

unchecked })public void startServer() {try {System.out.println(thrift server host on port 8899);TServerSocket serverTransport = new TServerSocket(8899);Hello.Processorprocess = newProcessor(newHelloImpl());Factory portFactory = newTBinaryProtocol.Factory(true。

以及一些测试程序代码等 2 编译生成.NET库(DLL)和Java库(Jar) 解压thrift-0.9.3.tar.gz文件,即可生成Thrift.dll 我的环境是VS2010以及.NET 4.0 (2) 生成Java库 Java库是通过Ant构建的,转载请注明出处:jiq钦s technical BlogApache Thrift 是 Facebook 实现的一种高效的、支持多种IT之家语言的远程服务调用的框架,引入Thrift.dll;然后还要将生成的Hello.cs也加入到工程中,生成的文件也都差不多,将之前ant编译生成的相关的jar文件(libthrift-0.9.3.jar以及E:Thrift hrift-0.9.3libjavauildlib目录下所有jar文件)add tobuild path;然后还要将生成的Hello.java也加入到工程中, (1) 生成.NET库 打开工程:E:Thrift hrift-0.9.3libcsharpsrcThrift.sln 编译。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using Thrift.Transport;using Thrift.Protocol;namespace ThriftTest{class ClientTest{static void Main(string[]args){TTransporttransport = new TSocket(localhost,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://www.juheyunku.com/jiaob/net/10635.shtml

最新文章
如何给asp.net core写个中间 如何给asp.net core写个中间

时间:2021-01-03

.Net微信网页开发解决用户 .Net微信网页开发解决用户

时间:2021-01-03

c++中Socket通信函数之WSAS c++中Socket通信函数之WSAS

时间:2020-12-29

提高生产性工具 提高生产性工具

时间:2020-12-29

全新的membership框架Asp.ne 全新的membership框架Asp.ne

时间:2020-12-29

不用找了,比较全的signal 不用找了,比较全的signal

时间:2020-12-29

计算字符串中每种字符出 计算字符串中每种字符出

时间:2020-12-29

EntityFramework 5.0 CodeFirst 教 EntityFramework 5.0 CodeFirst 教

时间:2020-12-29

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

Thrift实现C#调用Java开发步骤详解

2020-12-29 编辑:网友投稿

安装步骤这里就不赘述了, 8899);TProtocolprotocol = new TBinaryProtocol(transport);test.Hello.Client client = newtest.Hello.Client(protocol);transport.Open();Console.WriteLine(Client calls client.helloString().....);Console.WriteLine(client.helloString(jiyiqin));client.Dispose();}}} 7 运行 运行java服务端Server.java: thrift server init thrift server start thrift server host on port 8899 get jiyiqin 1 运行C#客户端代码ClientTest.cs Client calls client.helloString()..... Hello jiyiqin 1 请按任意键继续 可以看到Thrift和ICE等跨语言RPC框架开发步骤非常相似。

1 下载Thrift 下载地址: thrift-0.9.3.exe 用于编译Thrift中间文件生成对应语言代码的工具 thrift-0.9.3.tar.gz 包含Thrift各个语言的源码库,需要安装Ant。

true);Args args = newArgs(serverTransport);args.processor(process);args.protocolFactory(portFactory);TServer server = newTThreadPoolServer(args);server.serve();} catch (TTransportException e) {e.printStackTrace();}}publicstaticvoidmain(String[] args) {System.out.println(thrift server init);Server server = new Server();System.out.println(thrift server start);server.startServer();System.out.println(thrift server end);} } 6 编写C#客户端代码 新建普通控制台项目,几乎相同, (1)首先编写接口实现类: package test;import org.apache.thrift.TException;import test.Hello.Iface; public classHelloImpl implementsIface{privatestaticintcount= 0;@OverridepublicString helloString(String word)throwsTException {count += 1;System.out.println(get + word + +count);return hello + word + + count;} } (2)编写寄宿代码, , 5 编写Java服务端代码 新建普通Java项目,但是和基于Servlet的Hessian这种跨语言RPC框架差别较大, 打开命令行CD到java库代码所在的路径:E:Thrift hrift-0.9.3libjava(包含build.xml) 然后直接执行ant命令即可发现build目录下生成对应的jar文件,启动并监听在指定端口: package test;import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol.Factory; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.server.TThreadPoolServer.Args; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TTransportException; import test.Hello.Processor; public classServer {@SuppressWarnings({rawtypes。

类似的跨语言RPC框架还有ICE、Hessian、Protocol Buffer、Avro等,注意包名, 3 编写thrift中间文件namespace java testnamespace csharp testservice Hello {string helloString(1:string word)}4 生成Java和C#各自的接口文件 Thrift-0.9.3.exe gen java test.thrift Thrift-0.9.3.exe gen csharp test.thrift 可以看到在当前目录下会出现生成的对应代码。

unchecked })public void startServer() {try {System.out.println(thrift server host on port 8899);TServerSocket serverTransport = new TServerSocket(8899);Hello.Processorprocess = newProcessor(newHelloImpl());Factory portFactory = newTBinaryProtocol.Factory(true。

以及一些测试程序代码等 2 编译生成.NET库(DLL)和Java库(Jar) 解压thrift-0.9.3.tar.gz文件,即可生成Thrift.dll 我的环境是VS2010以及.NET 4.0 (2) 生成Java库 Java库是通过Ant构建的,转载请注明出处:jiq钦s technical BlogApache Thrift 是 Facebook 实现的一种高效的、支持多种IT之家语言的远程服务调用的框架,引入Thrift.dll;然后还要将生成的Hello.cs也加入到工程中,生成的文件也都差不多,将之前ant编译生成的相关的jar文件(libthrift-0.9.3.jar以及E:Thrift hrift-0.9.3libjavauildlib目录下所有jar文件)add tobuild path;然后还要将生成的Hello.java也加入到工程中, (1) 生成.NET库 打开工程:E:Thrift hrift-0.9.3libcsharpsrcThrift.sln 编译。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using Thrift.Transport;using Thrift.Protocol;namespace ThriftTest{class ClientTest{static void Main(string[]args){TTransporttransport = new TSocket(localhost,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://www.juheyunku.com/jiaob/net/10635.shtml

相关文章

风云图片

推荐阅读

返回ASP.NET频道首页