Page 1 of 1

.net assemblies and PHP, Windows server

Posted: Thu May 01, 2003 9:56 am
by cityhawk
Hello,

I am developing a .NET application that I wish to expose to PHP. In the past, I would have used COM for this. On doing a web search, I discovered that there is something called a Mono extension for PHP which allows PHP to access .NET assemblies.

However, the documentation seems to assume PHP5 and Linux server. I don't see where one gets PHP5, and I have a Windows server. So when I downloaded the mono extension for Windows, none of the directions make any sense.

Does anyone here have experience in calling .NET assemblies from PHP, especially on a Windows 2K server?

Alternately, is there a way to exploit the .NET framework's "COM Callable Wrapper" such that the .NET assembly "looks like" a COM object to PHP?

Thanks!

Posted: Thu May 01, 2003 11:10 am
by cityhawk
I have found an answer to my own question, and thought I'd post here in case anybody else was curious.

If you register the .NET assembly for COM interoperability (which can be done in Visual Studio .NET or manually by using RegAsm.exe) then, PHP will be able to "see" the assembly as if it were a COM object. I have tried it with a simple C# class library and it works great (even better than the COM did originally, in terms of all the parameter/return value mumbo jumbo you had to do to get data into and out of your interface methods in the COM object). Here, you just create a class with public functions. Then you can just create an instance in PHP by doing something like:

$instance = new COM("AssemblyName.ClassName") or die("Unable to instantiate blah blah");

//Then just call the functions:
$returnValue = $instance->Foo($param1, $param2, $etc);

//It's as simple as that.

To set up the assembly to emulate a COM object in VS .NET, if you right click on the project in the ClassView window, and select "Properties" (I couldn't find a "Properties" choice in the Project menu on the main menu bar), then select Configuration Properties/Build from the treeview on the left. Then in the section labelled "outputs", set "register for COM interop to True.

Good luck!