Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Access .net object from PERL

by Shaune (Novice)
on Apr 24, 2006 at 16:38 UTC ( #545321=perlquestion: print w/replies, xml ) Need Help??
Shaune has asked for the wisdom of the Perl Monks concerning the following question:

Ok I know Microsoft is a dirty word, but I have no choice right now. I have an existing application with a large number of perl modules. Unfortunally I need to now encorporte some 3rd party .net functionallity. How do I access a .net library from my PERL code? It was easy enough to do the old OLE or COM objects, but I have found no help accessing .NET I know Activstate has a perlnet SDK but all i found on it was was to let .net use PERL, not the reverse. HELP! Shaune Donohue

Replies are listed 'Best First'.
Re: Access .net object from PERL
by marto (Bishop) on Apr 24, 2006 at 16:57 UTC
Re: Access .net object from PERL
by jimbojones (Friar) on Apr 24, 2006 at 18:41 UTC

    Another possibility is that the .NET dlls can be exported as COM objects, and then you could access them as usual. Depends on the 3rd party, I guess.

    You could write a .NET wrapper to the 3rd party code that calls the methods you want, and then you can export your wrapper code to COM. I've been doing some of this lately (exporting .NET to COM for 'legacy' apps), so /msg me if it's something you'd want more details on.

    HTH, J


      As a follow-up to the above, here's how you can wrapper .NET code and expose it to COM, making it available to Perl. The following example wrappers the .NET System.Console.Write and System.Console.WriteLine methods.

      What does "as usual" mean, in Perl terms?

        Sorry, "as usual" was probably an over-statement. The OP said "It was easy enough to do the old OLE or COM objects," so I assume there is some way to do it with COM objects through Win32::OLE. My experience of late has been to invoke .NET dlls from legacy C apps through COM wrappers. I haven't done this with Perl, but putting it all together (.NET -> COM -> Perl thru OLE ) should work.

        - j

Re: Access .net object from PERL
by philcrow (Priest) on Apr 24, 2006 at 18:42 UTC
    I have a somewhat extreme suggestion. Perhaps you could wrap the third party code with something that exposes it as a SOAP or other web service, then use standard libraries (SOAP::Lite, etc.) to hit it?


      Actually that is not all that extreme a suggestion, two approaches are available: either to explicitly create an ASP.NET web services facade for the .NET APIs or to create a small wrapper that exposed them using HTTP Remoting. The former is probably the more flexible and depends less on the way that the API has been designed. The great advantage of using SOAP rather than, say, COM interop is that you are not limited to having the Perl parts of your application run on Windows.


Re: Access .net object from PERL
by pKai (Priest) on Apr 24, 2006 at 22:19 UTC
    ActiveState's PerlNET does give you the feeling to use .NET assemblies in "Perl syntax"
Re: Access .net object from PERL
by jimbojones (Friar) on Apr 24, 2006 at 22:35 UTC

    One more thing along the lines of wrappered .NET code and the ActiveState perlNET SDK: .NET supports reflection, so you might be able to write a .NET COM-exposed dll 'reflector' that you access thru OLE. The 'reflector' would take as input your 3rd party dll, and return an object that wrappers your 3rd party code. It's more work, but it's also more general than wrappering every method you want to expose. I suspect that's what perlNET from AS does under the hood (with a lot more syntactical sugar thrown in).

    - j

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://545321]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-02-24 11:01 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (354 votes). Check out past polls.