Jul 8 2009

Using Silverlight to consume a simple php service with WebClient

Suppose you have some php services which return a string using this simple code:

phpInfo.php:

<?=
phpInfo()
?>

phpGetExample.php:

<?
if($_GET['name'])
{
$name = $_GET['name'];
}
echo 'The service returned: ', $name
?>

You can consume this services by your Silverlight application using the WebClient class:

 

<UserControl x:Class="phpTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/ presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">

<StackPanel x:Name="LayoutRoot" Background="White">
<Button x:Name="btnCall" Click="btnCall_Click" Content="Call php"/>
<TextBlock Text="Result:"/>
<TextBlock Text="" x:Name="txtResult" Height="80"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnCallPar" Click="btnCallPar_Click" Content="Call php with parameter"/>
<TextBox x:Name="txtParameter" Text="Enter your name" Width="200"/>
</StackPanel>

<TextBlock Text="Result:"/>
<TextBlock Text="" x:Name="txtResultPar"/>

</StackPanel>
</UserControl>

And in code behind:

 

<?
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}

private void btnCall_Click(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += (s1, e1) => txtResult.Text = e1.Result;
wc.DownloadStringAsync(new Uri("<YourPhpUriHere>/phpInfo.php", UriKind.Absolute));
}

private void btnCallPar_Click(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += (s1, e1) => txtResultPar.Text = e1.Result;
wc.DownloadStringAsync(new Uri("<YourPhpUriHere>?name="+txtParameter.Text, UriKind.Absolute));
}
}

Read here the original post on the Siverlight forum and download the source code.


Sep 2 2008

Silverlight, PHP and WS-I Basic profile

Take a look at this great discussion on the Silverlight forum, about Web-Services interoperability.

As described, Web-Services must be implemented following the specifications reported on the WS-I Organization site.


Jul 8 2008

NetBeans IDE 6.5 MileStone 1 available

The new release is available for download.

Arun Gupta has posted a nice article on his blog describing the new features:

PHP

  • Enhanced Code Completion
  • Database-related code snippets
  • Multiple project configurations
  • Find Usages

Ajax

  • JavaScript Debugger
  • JavaScript Library Manager
  • Bundled JavaScript Libraries

Groovy

  • Editor
  • Java SE Project Integration
  • Grails support

Java

  • Javadoc Analyzer
  • Call Hierarchy
  • CamelCase code completion

Debugger

  • New Multithreaded Debugging Support
  • Debugging Window
  • Current Thread Chooser

Additional enhancements have been made to

  • Web Frameworks (Spring, Hibernate, JSF, JSF CRUD Generator, JPA)
  • Ruby
  • Database
  • Mobility
  • GUI Builder
  • Web Services
  • Improvements to XML and Schema Tools

Jul 2 2008

CodeGear, Delphi and RIA development

Thanks to this post by Marco Cantù, I’ve found two interesting articles by Justin James about the future of the Embarcadero/CodeGear development environments:

 

Justin states that ”CodeGear’s .NET products are expanding in new directions, which include RIA development and targeting other platforms (through systems such as Mono)”.

Will we be able to write rich internet applications using Delphi and targeting both .NET and Mono platforms?


Nov 17 2007

PHP Java Bridge

I’ve just tried to run PHP applications inside IBM WebSphere 2.0 Community Edition using the free PHP Integration Kit available on the IBM site, but it seems no more supported.

A better tool, based on a Open Source project called PHP/Java Bridge, can be downloaded from SoundForge.

The installation is very simple:

- install PHP (remember to enable the java extentions in the php.ini file);

- install WAS CE 2.0;

- log-on to the administration console and deploy JavaBridge.war included with the bridge.


Nov 9 2007

PHP and SOA

An interesting article,”Integrating PHP into Your SOA Solutions” by Rikki Kirzner, shows how to integrate PHP applications in an existing Service Oriented Architecture using: