From PHP to C # and vice versa

I am in this project:

A web page that will be used by Front-End members to request and update data from an SQL database. I work with a visual studio, and the code behind (C #) is almost complete, so the interaction between SQL and C # is fine. My initial idea was to work with ASP.NET, which is familiar to me, but it will not. I need to switch to PHP. So, today I am learning PHP for the first time by checking out http://php.net/manual/en/index.php , and many things seem very similar to ASP.NET, so I guess it won't be that hard.

In any case, some questions arose rather quickly, since I wanted the script to be something else than "hello world".

Is there an easy way to get / send C # variables from my class using php page? I read all about using XML to do this, but still I'm scratching my head, is there another, easier way to do this?

+7
source share
1 answer

You have options.

  • direct integration. PHP can create and use .NET objects. See the DOTNET library in PHP. Therefore, if you run PHP on Windows and you find your .NET logic in accordance with the requirements of the PHP DOTNET framework, you can simply call .NET classes directly from PHP. Some limitations: PHP is built to integrate with the .NET 2.0 runtime. You cannot create .NET 4.0 objects and connect to them with PHP.

  • synchronous network protocols. Like others, you can open your C # logic through the aREST or web services interface, and then call these services from PHP using the curl library or file_get_contents() . C # logic may be, but not necessarily publicly. In other words, you can only make it accessible from the firewall of your application so that there is no anonymous public access. on the other hand, your architecture may require access to the same API from third-party or user applications. In this case, it should be published publicly.

    either public or private, you will want to use WCF or ASPNET MVC to provide these services implemented in C #.

  • asynchronous mechanisms. PHP can connect to MSMQ. See Using PHP to Open MSMQ Queues . Of course, C # can do the same. You can use MSMQ as a mechanism for buffering communications between two worlds. To do this, you need to come up with a protocol for serializing data for messages that you put and get into the queue. JSON or XML would be the appropriate choice here.

  • Database. If you are concerned about using MSMQ, as this is “another piece of management infrastructure,” you can also use the database as an intermediate. Access to the common database can be obtained with both PHP and C # and can be used as a message queue or communication channel. PHP inserts messages into a MySQL table, and a C # application can read and process them, and then place response messages in another table. To do this, you will need some work to develop message formats, protocols, indexes, and a request / response correlation mechanism. But it relies on proven, existing technologies that you already know how to use.

  • Finally, there is a Phalanger. This allows you to compile PHP on the .NET Framework. This means that the integration between C # and PHP will be easy. I have not tried this, but it could satisfy your requirements.

+11
source

All Articles