How to host a WCF service in native C++ program

Go To StackoverFlow.com

2

I have a Windows Communication Foundation (WCF) service programmed in C#. I need to host it inside my C++ MFC native application (no C++/CLI). I don't know how to do that. The client is also a C# application.

Can anyone help me out?

2012-04-04 07:13
by Liton
in visual studio? is there a way to add service reference in IDE? : - Bip 2012-04-04 07:16
Why exactly do you want to do this? What is the requirement? Please help us out with the "context" of your question - that will help us give you a better, more informed answer. IMHO.. - paulsm4 2012-04-04 07:19
@PredragPejic - So you are saying that since add service reference in not in the IDE, I can't do that. very funny indeed : - Liton 2012-04-04 08:03
@paulsm4 - We have a large C++ native application. There are some client applications which use the services of this native program. One of these client apps is planned to run on Windows 8 Tablet (or on iPad/Andriod in the future). To achieve this we wanted to program a WCF service which will be hosted inside the native app, communicate directly with the internals of the app and provides services to the WCF clients (tablet app in this case). Thanks - Liton 2012-04-04 08:11
converting the wcf service to a windows web service with the wwsapi isn't a option - João Augusto 2012-04-04 08:55


1

OK - If you want a WCF service, I'd strongly urge you to implement the service in .Net and publish it with IIS.

I'd urge you to forget about MFC. Especially if you're considering Windows Tablet 8. Or Apple iPad!

For truly portable tablet clients, I'd strongly urge you "think HTML5" and look at a framework like AppCelerator Titanium or PhoneGap:

Finally, if you want your WCF service (or any .Net functionality) to "communicate with the internals of your C++ program", you've got lots of choices. Including "Interop": declaring an external reference and simply making a subroutine call into your unmanaged (C++) code:

IMHO...

2012-04-04 16:09
by paulsm4
Due to complex legacy application, I can't implement the first part of your suggestion. But the second part works for me. Thanks - Liton 2012-04-10 11:23


-1

I think this will help you:

http://icoder.wordpress.com/2007/07/25/consuming-a-wcf-service-with-an-unmanaged-c-client-with-credential-passing/

How to connect a C++ COM To a WCF Service

2012-04-04 07:25
by Nahum
Consuming a WCF service in C++ - not difficult. Implementing a WCF service (which is what I think the OP wants to do) - also possible. Implementing a WCF service in an C++/MFC .exe - huh?!? I'm truly baffled why the OP wants to do this.. - paulsm4 2012-04-04 07:34
@paulsm4 do it without having .exe? erm. maybe you can convert the MSIL exe to nativecode one and than use one of those programs that can pack dlls in same file as exes - Nahum 2012-04-04 07:38
@Nahum Litvin I can connect to WCF service from C++ program. But I want to host the WCF service inside a C++ native program so that it can communicate with the internals of the C++ program - Liton 2012-04-04 08:16
Ads