开发者

Can WCF be used with/from native (C++) applications?

What the question says. How do you interface with the WCF "world" from a native application, that does not have .NET available?

EDIT: Sorry, I should have been more specific as it appears that WCF covers such a broad spectrum. I was thinking of the case wher开发者_C百科e you have several applications using WCF/TCP communication as their communication/IPC mechanism and you now need to integrate a native (C++) application that hasn't .NET available.


WCF is protocol agnostic - well almost. But you need to consider this in the way you are going to communicate with WCF:

As long as you can send messages as the other side can use, you should be alright.

1) Named-pipe binding: It is propriety and difficult to use outside .NET

2) TCP binding: It is propriety and difficult to use outside .NET

3) basicHttp binding: It is one of the easiest to implement outside .NET

4) wsHttp binding: as long as you have a nativelibrary that can create and consume ws* messages you are fine but a bit difficult.

5) REST API: It is indeed the easiest and I recommend this one if you have a control over what kind of service is provided to you.


Yes, it is possible to have an unmanaged C++ application communicate with other applications using WCF. In my particular situation, I've modified a legacy MFC executable to communicate with a Windows service using WCF.

The basic idea is to write the WCF client code in a .NET assembly using C# since it's just easier to do this way. Then, use a C++ dll to bridge the gap between the unmanaged C++ code and the .NET assembly.

I've got some step-by-step instructions for how to do this here.


You can consume WCF services from native code (without bridging to managed code) by using the Windows Web Services API on Windows 7 and Windows 2008 R2 or later OSes. WWSAPI is a native code implementation of SOAP which supports the WS-* and .NET-* family of protocols, and which has a minimum memory overhead.

WWSAPI include a handy WsUtil tool to generate C stub code for the interface from the service description document. You can generate a WSDL service description document with the Service Model Metadata tool SvcUtil documented here.

There is also helpful MSDN blog article demonstrating how to call a WCF service from native code using WWSAPI.

If you are coding in C++11 and your WCF service exposes REST interfaces, then there is a more modern alternative API (also by Microsoft) for consuming REST services called Casablanca, documented on MSDN here, and hosted on codeplex here.


The "WCF World" that is not using a standard SOAP protocol is the problem. NetTcpBinding and NetNamedPipeBinding need some kind of unmanaged to managed bridge as described. So the answer not obviously "yes". It depends on the binding provided by the WFC service.


I have no idea what "WCF world" you're talking about. WCF can be used to implement SOAP web services, either using the old SOAP 1.1 formats, or the modern WS-Security. So, your question becomes: can I call a SOAP web service from C++, and the answer is obviously "yes".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜