views:

76

answers:

2

Can I have a VB6 app call a named pipe connection to a service written in C# with a WCF endpoint?

The VB6 project that makes use of named pipes to talk to a service written in C++. I would like to convert the C++ service to C# (.NET 4.0 preferably).

The VB6 project uses a Win32 call to CallNamedPipes to send a message to the server. The payload of the message is a string that consists of the following structure.

 [command][data length][data if approprate to the message]

I am not able to convert the VB6 side of the application at this time but I am wondering if I can rely on the CallNamedPipe function to send a message to a new WCF service and if they will play well together. I would see the contract side of the WCF service basically being one method that accepts a string that I will parse.

Also, since CallNamedPipes can receive return data in the outputBuffer parameter, would WCF be able to accomodate this? Would the contract be something like this...

string DoSomething(string command)

Thanks for your help!

Brian

+1  A: 

WCF is very good, but really shines when using WCF on both sides of the communication channel. Trying to hook up legacy code to a WCF service is tricky at best.

It will likely be easier to make your C# service use NamedPipeServerStream directly. This will give you complete control over how the connection and transfer is handled. That being said, there is nothing preventing you from doing both (implementing a custom NamedPipeServerStream channel, as well as exposing one or more WCF endpoints, from within the same program). This would provide a way to move forward if you ever want to upgrade the client, as well.

Reed Copsey
With a NamedPipeServerStream, can I send back return data or would I be basically doing some type of bidirectional communication on the pipe so that the client would need to "listen" for return data? I would love to upgrade the client but right now it's not in scope and not sure if it ever will be.
Brian Behm
@Brian: You'd basically just do whatever your C++ program is currently doing - it's possible to do bi-directional communication in a single pipe - but I'm not sure what your current program is expecting.
Reed Copsey
@Reed currently the VB6 code calls with a command like "GiveMeSomeInfo" to the service, which returns the info in the outputBuffer provided by CallNamedPipe. So really it's used like a remote method call. Like you say I could do exactly what the C++ code is doing and PInvoke the Win32 code to setup the named pipe and return the data. I was kinda hoping to make WCF work.
Brian Behm
@Brian: I was more thinking you could use NamedPipeServerStream, on the C# side, to mimick what the C++ code was doing with the Win32 API... It's really a fairly thin API wrapper (that lets you use Stream classes, etc).
Reed Copsey
Unfortunately, WCF really kind of dictates the format (on both sides of the channel), so to make it work cleanly with legacy code is not trivial..
Reed Copsey
A: 

Brian,

Could you call the C++ named Pipes application directly from your C# code using PInvoke

Pinvoke.net

Then the wrap the pinvoke service around a WCF Service for easy interop.

Regards

Iain

Iain
I want to call from VB6 to a new C# application. The goal is to get rid of the C++ code.
Brian Behm