This is one of a series of blog posts about my experience competing in the European WinPHP Challenge 2009. Sponsored by iBuildings, Microsoft and Leaseweb, competitors are asked to build a PHP app for Windows Server 2008 and IIS 7 to showcase the FAST in FastCGI. The winner gets travel and tickets to Microsoft MIX 2010 in Las Vagas in March. My entry is Give It A REST , a SOAP <-> REST gateway.
My first problem to solve in R&D is simple: given a (possibly remote) WSDL, how do I create a piece of compiled .NET code to call the described web service? The last time I did any regular Windows development was back in the Win16 days; this is going to be quite a steep learning curve for me.
Finding The Relevant Microsoft Tools
MSDN – Microsoft’s Developer Network – is (AFAIK) the place to go to find Microsoft’s documentation for software development. Clearly, there is a lot of information on MSDN. But how do I quickly find what I need to know … when I don’t really know exactly what I’m looking for? This is a substantial weakness of the MSDN site.
In the end, I had best success using Google to search MSDN. It’s also worth looking at information provided by your SOAP service vendors; Netsuite (for example) publishes a very clear walkthrough of how to do exactly what I need to achieve too.
The .NET framework ships with a command-line tool called wsdl.exe. In my Windows Server 2008 install, it can be found in C:Program FilesMicrosoft SDKsWindowsV6.0ABin. It can do all sorts of useful things, but at the most basic level, it can create a C# source file from a (possibly) remote WSDL file:
If there are problems validating with the WSDL file, they appear in the output to the screen:
This is something I’ll need to make sure I support in the final app, where wsdl.exe will be called automatically from PHP.
As expected, it takes a few seconds for wsdl.exe to complete. The length of time depends on the time it takes to download the WSDL file and the complexity of the web service described. Rather than do this from front-end PHP code, I’ll need to trigger this from some sort of backend queue to ensure the best quality user experience. This is something I’ve anticipated, and it’s already on my R&D todo list 🙂
Examining the .cs File
I’m very pleased to say that wsdl.exe generates a single C# file containing all of the classes required for the SOAP client. That really makes my life a lot easier 🙂 It also illustrates why having auto-generated SOAP clients is so important: the C# file for the Netsuite 2009 SOAP service weighs in at a “mere” 186796 lines of code!
Can you imagine having to create that by hand?
Compiling The SOAP Client
To compile the .cs file from the command-line, I need the .NET framework compiler, csc.exe. On this fresh install of Windows Server 2008, there are multiple copies of csc.exe to be found; one copy per installed .NET framework. The latest version (and hopefully the best version to use for this project) is in C:WindowsMicrosoft.NETFrameworkv3.5.
Creating a basic DLL (dynamic link library; roughly similar (but not quite) to a Linux .so dynamically-loaded library) from the auto-generated C# source code is very easy:
The result is one Windows DLL file. My next step is to figure out how to call this from PHP.