You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Paul Chen <po...@gmail.com> on 2011/09/02 01:59:15 UTC

Using c# wrapper to implement windows thrift server

Hi,

I am trying to implement a thrift server on windows. We currently have OS X
up and running just fine. Of all the possibilities to try and get the thrift
runtime running under windows, I am currently pursuing the use of the c#/CLR
implementation of thrift and creating a C++/cli wrapper to bridge to our C++
implementation.

I was hoping to re-use our C++ service implementation, but I've hit a snag.
Our interface uses structs but to compile the C++ code, I need <thrift.h>
but that doesn't work so well under windows (i.e. need <netinet/in.h>,
reference to ctime_r, etc). So the way around this is to add a layer above
the implementation that adapts the parameters away from thrift structs. For
example, in pseudo C++

class MyServiceImpl : public MyServiceIf
{

    public void MyMethod(common::MyStruct& struct);

}

would be changed to

class MyServiceImplWrapper : public MyServiceIf
{

    public void MyMethodWrapper(common::MyStruct& struct);

}

class MyServiceImplNative
{

    public void MyMethod(Bar& bar, Foo& foo)

}

Where MyServiceImplWrapper::MyMethodWrapper()
calls MyServiceImplNative::MyMethod() while translating common::MyStruct
into a Bar and a Foo.

If my C++ code is laid out as above, then I "only" have to implement the
MyServiceImplWrapper class in C++/cli to covert the thrift struct as well as
cross the clr/unmanaged boundary. In other words, I add an adapter layer to
simplify my implementation on the C++/cli side at the expense of what seems
like a superfluous layer looking at it from the OS X C++ side.

Am I missing something? Is there a better way to do this? Rewriting my
implementation completely in c# is not an option since our backend is in
C++.

Thanks in advance,

Paul