Girauder
Girauder

Reputation: 185

How to add Thrift dependencies to a C# project?

Hi I'm trying to use Thrift for a project on Windows, however I don't seem to understand how to get it to work and I don't understand the documentation provided very well either. So far I managed to create the thrift compiler and use it to generate java and c# files. However, when it comes to using them in a simple project I seem to get stuck in the same part. Right now I'm following this tutorial:

http://blog.rfaisal.com/2013/10/09/getting-started-with-apache-thrift/

Which has been quite helpful but, I still don't understand how to add the language libraries, In the tutorial for instance he says:

"At this point, you need to add the thrift library to your project. Open the Thrift C# library from the tarball (should be under /lib/csharp) and compile it."

Later for the Client he says: "Copy the Thrift Java library from the tarball (should be under /lib/java) to this project."

I have both folders, but I'm unsure as of what exactly I should do.

Could someone point me in the right direction?

Upvotes: 1

Views: 2071

Answers (2)

Girauder
Girauder

Reputation: 185

The problem I had was with adding the dependencies to the projects.

For c# one need to open the thrift solution, then select "Release" under build configurations and build it. Then under bin/Release you find the .dll file you need to reference in your project.

For java you need to add the whole org folder to your project and then you need to add the httpclient-version.jar and httpcore-version.jar to the build path

Upvotes: 0

JensG
JensG

Reputation: 13421

There is a tutorial on the Apache Thrift web site which serves as a good start.

The Compiler comes prebuilt for Windows, so you theoretically do not need to build it on your own, but it isn't that hard either. At the end, that's a detail.

Regarding the libraries for C#, you have two options. The recommended one is to compile the Assembly using the project file under /lib/csharp/src. The other option is to simply include all the files into the project.

Of course, you only use the languages you need. If you want C# only, ignore Java. Thrift supports about 20+ languages on multiple platforms, you pick whatever you need and ignore the rest.

Same with the generated files: Either include them into the project or create an assembly, like it is done for the test under lib/csharp/test/ThriftTest.

The basic workflow is for all languages the same:

  • create an IDL file to represent your API contract
  • call the Thrift compiler to generate code
  • put together the desired protocol/transport stack
  • flesh out client and/or server code
  • build everything
  • be happy.

Upvotes: 0

Related Questions