dingoglotz
dingoglotz

Reputation: 2833

Connect unmanaged c++ to WCF using TCP Binding

I have a WCF Server written in C# and use netTCPBinding to communicate with the clients. Now I want my unmanaged c++ Client to connect to the same WCF Server. Is this possible? Do the C++ Clients can have the same functionality as the C# Clients? If it is possible, how can I do it? I read something about making a bridge dll between c++ Client and C# Server, but the tutorial is quite old and all of the templates are missing in Visual Studio 2013 Express.

Upvotes: 2

Views: 1755

Answers (1)

Alex F
Alex F

Reputation: 43331

Take a look at Windows WEB Services API:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd430435%28v=vs.85%29.aspx - main page

http://msdn.microsoft.com/en-us/library/windows/desktop/ee354195%28v=vs.85%29.aspx - code examples

This article shows how to make connection between native C++ code and C# WCF:

http://www.codeproject.com/Articles/38535/A-first-look-at-the-Windows-Web-Services-API

Note that interoperability between managed WCF and native client is restricted. Managed WCF exposes some features, like exception marshalling, callback interfaces, managed object serialization, which are not supported by native WWS API. You need to use simple binary communication protocol and make binary serialization (if necessary) manually on both sides. One way (asynchronous) WCF calls can be implemented as void methods in WWS API. Instead of callback inteface use server/client pair on both sides. I recommend you to use simple high-level WWS Service Model rather than Channel Layer, which is quite complicated.

From my personal experience: after testing WWS - WCF interoperability, I decided to implement communication level purely in WWS SDK, and expose this functionality for C# code through PInvoke. I would use WWS - WCF interoperability only if I need to communicate with existing WCF service that I cannot change.

Another way: add .NET support to native C++ project. Now you can use WCF by conventional .NET way. For example, you can add reference to C# Class Library that works with WCF, and call it from C++ code.

Upvotes: 4

Related Questions