OpenSolarDB - database - extract data - examples

Extract data - Code Examples

With Webservices  With AMF Remote calls

Webservices

Here you will find various code examples to connect your application to the database via a webservice. Of course not all posibilities are treated but the following selection of webservices has been made:

The Wsdl url where you can access the webservice is: http://opensolardb.org/wssolardata?wsdl . Here you can find autogenerated function documentation.

Excel sheet

An MS Office 2003 Excel sheet has been used with Windows XP as operating system. To make a web service client with Excel work, you need to do the following two things:

  • Download and install the Microsoft Office 2003 Web Services Toolkit, see this article.
  • Download this Excel sheet. This sheet contains some macros to extract data form the database with the web service. Be careful to open the Excel sheet with the macro security level on low or medium. If not, the added macros will be deleted. With the security level on medium, you are still protected enough.

This is a preview of the Excel sheet with data obtained from the web service:

Excel preview
Excel sheet preview
Necessary references in the Visual Basic Editor
References in Visual Basic Editor

Feel free to change the macros to your own needs.

In your Visual Basic Editor of your Excel sheet, you will need a reference to "Microsoft XML, V4.0" (Available in standard Windows XP) and to the "Microsoft Office Soap Type Library V3.0". (Available in the installed Web Services Toolkit). See the image on the right. Sorry, but my Office is Spanish. The refence list you will find in the top menu under 'Tools' ('Herramientas' in Spanish).

It may be that other versions of those libraries are also working, but have not been tested.

Java Application

A java application has been developed to demonstrate how to use the solar data webservice. The application has been developed with Eclipse GANYMEDE Version 3.4.2 with java virtual machine jre5. You can download the application here.

To generate in Eclipse the web service client base java classes is very simple. In the top menu, choose File→New→Other...→Web Service Client. The following window will pop up:

Create Web Service Client in Eclipse
Create Web Service Client in Eclipse

Fill in the service definition exactly as shown in the image. After pressing the 'Finish' button, Eclipse will generate all code to access the webservice, including java beans. To obtain a list of countries now is just as simple as:

OpenSolarDB_WebApiServiceLocator sl = new OpenSolarDB_WebApiServiceLocator();
ws = sl.getOpenSolarDB_WebApiPort();
Default_Model_Bean_Country[] countries = ws.getAllCountriesWithData();

Remarks:

  • You may have to add a toString function in the Default_Model_Bean_Country and Default_Model_Bean_Place classes if you want to use those classes to populate a combobox or other list.
  • Also be aware of the following. The longitude for a place is optional in the database. If the longitude has not been defined for a place, the function getPlacesInCountry

    in the web service client will not set the corresponding property in the Default_Model_Bean_Place object. So the longitude will be uninitialized which results in a zero in java. However, a longitude zero is a valid value (Greenwich) and therefore I initialize longitude on 999 in the Default_Model_Bean_Place class:

    private float longitude = 999;

 

Microsoft .NET Application
Create Web Service Client in Visual Studio
Create Web Service Client in Visual Studio

Also a .NET application has been developed to demonstrate how to use the solar data webservice. The application has been developed with Microsoft Visual C# 2008 Express Edition. You can download the application here.

Also in Visual Studio, it is very simple to generate the web service client base classes. Create for instance a Windows Forms application, right click on the project in the solution explorer and choose 'Add service Reference'. See figure on the right. The following window will pop up:

Create Web Service Client in Eclipse
Create Web Service Client in Visual Studio (2)

Fill in the address exactly as shown in the image and press the 'Go' button. A list of all webservice functions will be displayed. Now press the 'Ok' button to generate all code to access the webservice. To obtain a list of places (solar data measuring stations) in Spain is even simpler than in java (uh, that hurts...):

WSSolarData.OpenSolarDB_WebApiPortClient dataPort = WSSolarData.OpenSolarDB_WebApiPortClient();
WSSolarData.Default_Model_Bean_Place[] places = dataPort.getPlacesInCountry("ES");

The same remarks mentioned in the previous java section also apply for this .NET application.

 

Android App

Of course you can use the web services also in mobile applications. In Google Play you can find an app which is called Solar It! (made by XPaterna) with which you can dimension/design your solar home system. Though the app is in Spanish, it is pretty self explaiNing. You can find the application here.

 

AMF (Action Message Format) Remote method calls.

Here you will find an Adobe Air code example to connect your application to the database via AMF. The web function interface is exactly the same as for a Web service, so here's a link to the web service interface documention again. The so called 'amf endpoint' can be found at http://opensolardb.org/amfsolardata.

You can download the example code here. The code was created with Adobe Flash Builder 4 (built on top of Eclipse). You can also directly execute the demo air application here.

Remarks:

  • I had some mapping problems here. I couldn't map the result of the functions getSolarDataForPlace and getSolarDataForCountry to the class Default_Model_Bean_PlaceAndSolarData, although I could see (for instance with the tool ServiceCapture) that the data arrived correctly at the client. I circumvented the problem by reading the results without mapping it using the E4X technique.