Wednesday, June 25, 2008

.NET to PHP Connector


Wouldn't it be easy to call in .NET a PHP function, and retrieve an answer in the form of an .NET object?

I've looked around on the net and I haven't found a library that does such a thing.
Because I've made a site in PHP for managing kittens and nests (cat-site) etc, where users can add stuff as they want, the client requested to manage the clients and the nests etc, which is pretty logical, but implementing a controlpanel in PHP that does all that was requested was a little too much work, because I had a little budget to take in account.

So I've created a .NET to PHP connector (that I can re-use in other projects) for connecting to the kitten-server and retrieve information about nests etc...

I've also implemented it that way that there is a possibility to easyly change the security of the PHP-Connector.
For the moment the default security is base64. I'm sure there are better ways to send data from point a to point b, but the issue is that if you encode stuff, for sending it to the server, then you have to decode it on the other side also, and you need to decode it with PHP, while it's encoded in .NET, it's not always that easy.

The architecture is pretty easy, it's straight forward, and based on async calls to the server. The usage is also pretty straight forward:

  • Put the gateway PHP file and code file on the server;
  • Instantiate the Connector for connecting to the gateway URL;
  • Call the connector.SendQuery(involvedObject, "methodname", [arguments]);
  • Catch the receive answer event which gives you back your 'involvedObject' and an Answer object containing the server's response.

With this mechanism, I've created an administration tool, which is session-based with login system etc, you can name the gateway as you like, the mechanism only accepts POST requests, and the request are encoded... you can also define methods that may never be called from the connector for security reasons...

I know this system is not super secure, but you can adapt it to you own whishes, and extend it to your believes, it's just a primer where you can base yourselves on.

I will upload the code to a server soon when my project is ready and the code is stable enough, (it's almost ready ;))

Maye a graph would make it more clear how the system works :

Class diagram:

If you have any comments or suggestions, please feel free to leave them ;)


1 comment:

harada57 said...
This comment has been removed by the author.