views:

162

answers:

5

Hi:

I have some .dll native C++ programs which mainly return int/double values, array structures and string values. These values should be taken by a Web Service program made in C#.

I would like to know if it is really necessary to modify my C++ programs and adapt to Web service, i.e. return values such as a XML string/file together with a XSD string,/file. Personally I think I should not modify them because I think C# can receive C++ values using interop and easily serialize using components of .Net library.

However, I would like to receive comments about the best, fast and effective way to pass C++ values to a Web Service.

Thanks!!

+1  A: 

I think you can do it as you stated.
In the past, I achieved the same or similar by writing a C++/CLI wrapper around my native classes and consumed those from C#. This didn't incur the overhead of C# interop, which I've noticed can be quite expensive.

Shaun
That is new for me, I didn't know that C++/CLI doesn't need interop and doesn't generate an overhead. Do you have links which explain this interface with native C++? Thanks!!
It's not an "interface", which is why it performs so well. C++/CLI is the only .Net language that can be both native and managed in the same assembly. You basically instantiate an instance of you native class using the RIAA pattern and expose the same interface, passing off to the instance. Also C++/CLI is the only language with deterministic finalization, a big plus (at least for me)...Looking for my links, but I think my best resource was a book...
Shaun
Here's one link, which actually covers all your interop possibilities pretty well. At one time I had dozens of these, I'm still looking for more info for you.<br> http://msdn.microsoft.com/en-us/magazine/2009.01.clrinsideout.aspx#id0070020
Shaun
Shaun
A: 

I think P/Invoke is what you want here. It will allow you to pass your simple and composite types between managed and unmanaged code, and you won't have to write any C++/CLI wrapper assemblies.

This (MSDN) is a good start for P/Invoke. If you scroll down here's a section called 'Specifying Custom Marshaling for User-Defined Structs'. This will allow you to pass your user-defined structs back and forth.

Look up MarshallAs and you can see all the primitive native types you can marshall. The DllImport attribute is something you will want to search for as well.

If performance becomes an issue, I would recommend serializing/deserializing into either named pipes or a local socket, but I'm not totally clear on the performance chararistics there. Good Luck!

jscharf
A: 

The best, fastest, most efficient and effective way to expose your C++ application as a web service is to put C++ web service code on top of it.

See GSoap for a very fast, open source, implementation - one that is 3-5 times faster than the .NET and Java equivalents.

gbjbaanb
The performance report you kindly linked is from 2004, doesn't the situation changed for better since there?
A: 

As long as you can return it to C#, C# should be able to return it from a web service. You should not have to do any manual serialization at all.

John Saunders
A: 

If you choose to go the serialization route you might want to look at 'thrift' (http://incubator.apache.org/thrift/).

From the website:

Thrift is a software framework for scalable cross-language services development. It combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk, and OCaml.

Originally developed at Facebook, Thrift was open sourced in April 2007 and entered the Apache Incubator in May, 2008.

ajitomatix