Andri Yadi

Butterfly Effect
See also: Other Geeks@INDC

"Poisoning" PHP Developers at MSDN Day | PHP on Windows

On Thursday, May 15, 2008, I talk about Interoperability between .NET and PHP through XML/SOAP Web Services at MSDN Day | PHP on Windows. During my session, I do a little "poisoning" to PHP developers by showing to them how easy creating web services and proxy classes to access web services in .NET using Visual Studio. And it's quite successfull, a participant finally asks Visual Studio price since he is interested on Visual Studio features. I think I should be a Visual Studio marketer :)

But honestly, it's all about tool. I think the simplification of Web Services-related stuffs can also be done in PHP world if PHP IDE support those kind of stuffs. I don't know whether the famous PHP IDE, Zend Studio, support them. Please somebody from Zend Indonesia explain about Web Services-related stuffs. Honestly, I do wanna know to enrich my knowledge :)

For this MSDN Day, I have to install PHP runtime, PHP editor, and dig to well-buried PHP manual after I've left PHP for more than two years. For PHP editor, I still can't find a comprehensive and free PHP editor. Too bad I can't build one :) Since I love Visual Studio and I want to be able to create PHP script within VS environment, I finally find a plugin for VS to create PHP project. That plugin is called Vs.Php from Jcx.Software. The 30 days-trial version is available for download. Since I think I still have no intention to go back to PHP after 30 days later, I just install that trial version plugin, and sure I will uninstall it several days after the event :)

During this talk, I talk about:

  • Integration options between PHP and .NET
  • Web Services integration option
  • Calling ASP.NET Web Services using Microsoft AJAX Library from PHP or non .NET code

The presentation slide can be downloaded at: http://dycode.com/files/folders/msdnday/entry123.aspx

I do some live codings to show how easy to develop interop between PHP and .NET through XML/SOAP Web Services. For example, in #1 demo I create an ASP.NET Web Services, and then create the consumer of that web service in PHP script. For that purpose, I use a library called NuSOAP to develop PHP SOAP Web Service client.

ASP.NET Web Service code. This is deployed at URL: http://localhost/MiscWebServices/WebService.asmx

<%@ WebService Language="C#" Class="WebService" %>
 
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
    [WebMethod]
    public string GetServerTime()
    {
        return DateTime.Now.ToString();
    }
 
    [WebMethod(Description = "Get Server Time with supplied format")]
    public string GetFormattedServerTime(String format)
    {
        return DateTime.Now.ToString(format);
    }
}

And the PHP code as the client:

<?php
//Refer to NuSOAP lib
require_once('../../nusoap-0.7.3/lib/nusoap.php');
 
//Create WS client
$client = new nusoap_client("http://localhost/MiscWebServices/WebService.asmx?WSDL", 'false');
 
//Check if there is error
$err = $client->getError();
if ($err) {
    echo ('<h2>Constructor error</h2><pre>'.$err.'</pre>');
}
 
//Create param
$param = array();
 
//Call WS
$result = $client->call('GetServerTime', $param);
 
//Check error
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    echo '<h2>Result</h2><pre>';
    echo ($result['GetServerTimeResult']);
    echo '</pre>';
}
?>

What if the accessed web method need parameter(s)? Well, you can just supply the $param array with needed parameter(s).

 

I'm so glad to be involved in this MSDN Day. Hopefully, my talk can be a starting point to integrate your PHP to .NET or Windows platform.

That's it. Enjoy. Have a nice weekend.

Share this post: | | | |
Posted: May 17 2008, 02:36 PM by andriyadi | with no comments
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 
Are you human?:  


Enter the numbers above: