SILVERLIGHT & PHP INTEGRATION
Most reusable Technique. Bringing bridge between Silverlight and PHP.
|
Abstract
The Technique – to bridge between Silverlight and PHP this technique proven and accepted all over similar type of requirements. Intension of developing this technique was to establish communication bridge between Silverlight control and PHP which could be reused in any complex requirement;
Lets first answer “Why Silverlight and PHP ?”:
- Silverlight – Stateful model – .NET Framework – UI Capabilities – Cross-platform
- Leaverage best of both technology Silverlight and PHP worlds.
- PHP – Rapid application programming – Ideal as back-end using JSON or SOAP – Re-use your existing PHP logic
- Silverlight – Rapid rich user interface development – Create rich interfaces using a rich framework
Technique Pre-cursor
There was main challenge there was backend database and PHP service was implemented, need was to represent this data in Rich interactive application. There was another need that application should run not only in browser but as well as out of broswer mode.
|
We are strong supporter to develop frontend in Silverlight 4 as its cross browser and cross platform and leverages the .net framework ocean.it runs out of browser mode.
The challenge was how to fetch data from PHP service and in Silverlight and viseversa.
We had lots of brainstorming on it, we came up with some options like:
1. Writing WCF rest service wrapper –but there will be extra cost for service maintenance.
2. We also thought of using PHP nuSOAP – adding nuSOAP service refrenece in Silverlight, but we explored there is lots of complexity and limitations while handling collection data of different data types
Keeping in mind above challenges it was essential to come over this problem.
Solution description
|
Then after lot of googling, struggling and trial-&-errors. we gave thought on usage JSON. I referred some Silverlight forum, MSDN helps, and stared writing some code for proof of concept project.
JSON (JavaScript Object Notation) is a lightweight data-exchange format.I worked many sceniaro where are serialized and deserilised JSON data in Silverlight. So it was good thought that what if PHP response me JSON data and I use it in Silverlight to manipulate.
Refer the snap bellow that simplify, how the communication will happen between silverlight and PHP.
As snap says we need to 3 things in place:
- PHP service that response data
- Call PHP service method either using WebClient or HttpWebRequest
- Serialise,deserialse JSON data.
Pseudo Code for Sample Silverlight method that calls PHP service and pass emailed and password:
Pseudo Code for Sample PHP method that returns records from databased based on give parameters:
Pseudo Code for Sample Silverlight to handle service call completed event:
Pseudo Code for Sample Silverlight – Company class used for data deserialization:
So now you need to simply integrate silverlight control as object tag in PHP page alike you used to add in .html or aspx page. And make sure you have configured correct paths for PHP service call where services actuly hosted. below is the final flow of design.
- Your PHP services hosted those server processed data
- Silverlight control calls PHP service method with required parameters, either using WebClient or HttpWebRequest.
- PHP service processs parameter and return required response.
- On service call completed event gets the handle to the Silverlight control and passes the results to "DataBind" method.
- DataBind method desterilizes the JSON string to original object and performs the desired processing.
Thats it!!, just follow deployment easy steps and configure webpart and see experience.
Salient features
The salient Features of this innovation are:
- Simple technique that fulfill basic need of establishing communication between Silverlight Client control with PHP
- Easy to deploy.
- No restriction for Silverlight control development.
Competitive approaches
We learned this technique after lot of googling, struggling and trial-&-errors. First we searched for same type of sample applications so that we can reuse them, but only on few approaches like nuSoap Php service and Zend Framework was there, and after exploration I observed that:
- There was no any fullfledged proof of sample
- Lots of complexity and deployment challenges
- Additonal cost for developing or utilizing Zend framework.
And this was not helping me to solve my problems. Because I looking such technique that will give very dynamic commination of Silverlight client control to server code. So I started with my own code and came with very good, configurable custom silverlight webpart for Sharepoint.
Applicability
This approach can easily adapted to Similer kind of platform requirement like:
- Where you have already MySQL and PHP service environment and want to provide rich interface
- You want to leaverage clientside technology - Silverlight features like
- Run application out of broswer
- Printing
- Generate images
- Export to excel
- play audio/video
- and lots more…
Reference :
http://msdn.microsoft.com/en-us/library/cc197957(v=vs.95).aspx
|