Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

Comment on Access .net object from PERL
Re: Access .net object from PERL
by marto (Chancellor) 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
    Hi

    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

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

        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

      Hello

      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.

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?

    Phil

      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.

      /J\

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
    Hi

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://545321]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-09-18 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (124 votes), past polls