I have zero experience with COM. I actually never thought, I'll need to do something with COM, thinking it's something that I luckily managed to avoid. Oh, well.
I need to create a wrapper for Web Services, which could be used from COM. I was hoping, that it's a solved problem, but failed to find an easy solution (for example: just generating a wrapper from WSDL).
A sidenote: Apparently, I also can't use .NET Framework (I could solve my problem easily with the help of COMVisible attribute, right?), unless I'll prove, that it's not that hard to install it on hundreds of machines. Proving that seems easier than my other alternatives at the moment. Today is a weird day.
You can call a Web Service from just about anywhere, including VB6 and COM.
If you can create an XMLHTTP60 COM object, here's an SO answer that shows you how to use it: What is the best way to consume a web service from VB6?
Take a look at Python; it's almost trivial to create a COM server from Python (compared to most of the non-MS languages, at least), and it makes as good a COM client as any other language.
If your Web service isn't already written, it's also fairly easy to write them in Python as well.
Related
I want to create a deskband COM object for my pet project. I don't have any experience with COM and a quick search revealed that ATL will simplify things. I was wondering if there are any better ways to create a COM component today. Better in the sense less boiler plate, use of C# instead of C++ and any other things you may think of.
If deploying or relying on a .NET framework installation on the client machine is not an issue for you, than C# is much easier than C++ (although you will probably have to redeclare interfaces, IID, etc... in C#, using P/Invoke). If reducing dependencies is an issue, than C++ with ATL is better.
Just create it in C# and expose as a COM component, see this guide:
http://msdn.microsoft.com/en-us/library/zsfww439.aspx
The only reason I would consider C++/ATL is if I were connecting to any C/C++ libraries. Other than than I can't think of a strong reason to use C++ over C# (assuming your skill level is equivalent in both).
I can only recommend C++ in conjunction with Microsoft's ATL library.
I used some code generation tool written in C++ that helped me to get rid of quite a lot of boilerplate code. This tool generated code that produced more C++ friendly interfaces (like the code that gets generated in the tlh/tli files when you #import a type library in Visual Studio. My code generator produces similar code, only for COM servers.
If you are interested, send a mail to DerTopper at web dot de. Put something like "COM code generator" in the subject line, so that you won't fall through my spam filter.
Regards,
Stuart
I am developing a complex library in C++ and i plan on having a C interface so others can load up the DLL and easily access the lib. I haven't tried writing code in C# that access C code. I did a quick google and found code that uses a lot of attributes.
What can I do to keep my interface simple enough to not cause a headache trying to keep .NET in sync with it? Is there some kind of header generation tool i may use? Do i only use simple POD structs? I'm unsure how i should handle types as they are passed around as pointers. I am also thinking maybe i should avoid using anything that is a not an int/string or array.
I am developing it using MSVC but mostly using it with GCC. I know i should use the calling convention __stdcall. Beyond what i said i am totally clueless. I actually dont know how to load the DLL into .NET.
What can i do to ensure everything works correctly when writing my C lib and getting it to run with .NET?
Consider putting together a COM interface. Consuming COM from .NET is marginally easier than P/Invoke; at least you won't have to spell out prototypes for all functions in C#, the COM typelib importer will do that for you.
I'll explain breifly my situation and hopefully you will be able to advise if what im wanting to do is possible.
I have an existing java application that I am wanting to split into modules. To handle and control these modules Im going to write a module manager in C#.net. Due to the size of the existing program the bulk of the existing modules are not going to be rewritten in .net yet and remain as java modules.
Is it possible to call a java "module", pass it parameters and have the java module return a value ( other than an int )?
I apologise for not knowing much about this area.
Kind Regards
Ash
Hmm... maybe some kind of MessageQueues like MSMQ, Apache ActiveMQ or IBM WebsphereMQ can solve your problem.
On the queues you can store and receive XML-Messages with all the Information you need.
Some information about this can be found here:
http://msdn.microsoft.com/en-us/library/ms973816.aspx
Another approch can be to work with console output .. but IMHO this is not a good solution.
I would instantiate the Java as a separate service and call it using (say) web services, Hessian etc.
Alternatively, have you looked at jni4net ?
If everything's in Java, then why the effort in moving everything to C#? From what you've said it'd make much more sense to write the module manager in Java and just keep the codebase all in one language (unless of course I'm missing something, in which case ignore!)
If you really need to do this then I'd say a web service is the nicest way to go, there's other hacks and various tools around that you could use, but a web service would completely abstract the language away and makes things much easier to consume.
I haven't tried this either but hopefully reading this thread helps you... :)
Java - C# interop
You can expose your Java module as a soap web-service and consume it from C#.
Here you can read about Axis one of the Java Soap engines and quick tutorial how to create and call it from C#.
I'm working on an application where third party developers will be able to write plugins. I've been looking a little at Managed Extensibility Framework and it seems the right way to go.
One thing though, I want to prevent plugins from accessing the rest of the application freely (calling singletons etc) but would want to restrict to to communicate via some interface, ideally each plugin would have to "request" permission for different things like accessing other plugins and user data, is there a good way to do accomplish this?
Only thing I can think of otherwise is to have a security string passed to each method and obfuscate the hell out of the code but it seems like an ugly solution :P
What you need is a new AppDomain to be the sandbox for your plugin, but I don't think MEF supports loading exports into a separate AppDomain at this time (I'm sure someone will correct me if this is no longer the case).
If this is a serious concern for you, consider using the bits in the System.Addin namespace, and see this section on Activation, Isolation, Security, and Sandboxing for more information. It's a much more robust and secure alternative to MEF, but is far less flexible.
Update: Kent Boogaart has a blog post showing how you can use MEF and MAF together.
Does anyone have a good solution for integrating some C# code into a java application?
The code is small, so I could re-write in java, but I would rather reuse the code if possible. Don't repeat yourself, etc.
Also, I know I can expose the C# as a web service or whatever, but it has some security/encryption stuff in there, so I would rather keep it tightly integrated if possible.
Edit: It's going to be on a server-based app, so "downloading" another runtime is irrelevant.
You would use the Java Native Interface to call your C# code compiled into a DLL.
If its a small amount of C#, it would be much easier to port it to Java. If its a lot, this might be a good way to do it.
Here is a highlevel overview of it:
http://en.wikipedia.org/wiki/Java_Native_Interface
Your other option would be to create a COM assembly from the C# code and use J-Interop to invoke it.
http://sourceforge.net/projects/j-interop/
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
If it's short, I think you're better off re-writing the code in java. Downloading one 50Mb runtime is bad enough.
There is an IL to Java Bytecode compiler GrassHopper which may be of use to you. I've never tried it though.
I'd look at rewriting your code in Java though
EDIT: Note that Grasshopper seems to be no longer available.
We used JNBridge for this, and it worked great. It handles Java->.NET and vice versa, all in-proc.
If you do not want to rewrite hadle it as an Inter-process communication and choose one of following:
Named pipes
Sockets
SOAP
I would rewrite it if it's not too much trouble.
The web service would work, but it seems like that would be a lot of overhead just to reuse a little code.
http://www.infoq.com/articles/in-process-java-net-integration suggests running CLR and JVM in the same process space and passing calls back and forth. It sounds very efficient. I'm going to give it a try and integrate it into Jace if it works well.
If it is a piece of code that is exposable as a command line utility, I just make the other host language use a system call to execute the utility.
If your C# app needs to call Java, compile a special Java main that takes appropriate command line args and returns text output.
It the oldest, simplest method.
You can call your c# classes (compiled in a dll) via a bridging library, various libraries are available, every one with his characteristics. JNBridge generate proxy classes that you can call to manage the code in java classes. JCOBridge let you load your c# classes and use it from java using the invoke mechanism, also javonet let you import java classes and call java code using the invoke mechanism. All the explored solutions are commercial solutions that let you call java code from .NET and vice-versa with graphical user interface integration and other amenities.
Links:
jnbridge java-.NET bridge Developer and Deployment license schema with 30 day free trial
jcobridge java-.NET bridge Developer and Deployment license schema with unlimited Trial
javonet java-.NET bridge Research and Professional license schema with 30-day unlimited Trial after sign-up