This blog series will show you how to start
developing applications for Windows Phone 7. In this first blog, we will create
a REST Web Service on our SAP backend. In the second part, we'll see how to
consume this Web Service in a Windows Phone 7 application.
Building your first Windows Phone 7 Application (1/2)
Building Your First Windows Phone 7 Application (2/2)
Windows Phone 7
Windows Phone 7 is the new mobile
platform from Microsoft. However it is not just another mobile platform, Microsoft
has learnt from their mistakes with Windows Mobile. As we'll see in these
articles, one of the main advantages of Windows Phone 7 is the (freely
available) development platform. It is based on Silverlight and, as you might
expect from Microsoft, supported by excellent development tools.
A Simple REST Web Service
Instead of the old boring Hello
World stuff, let's use a simple REST Web Service to retrieve some sample flight
data from our SAP backend. We'll use the excellent generic controller developped by Uwe
Kunath to create it : RESTful webservices in ABAP using a generic controller (RESTful webservices in ABAP using a generic controller).
First of all use SAPLink (http://code.google.com/p/saplink/ (http://code.google.com/p/saplink/)) to install the different components on your system.
Then create a new ZCL_RESOURCE_FLIGHTS class that
implements the ZIF_RESOURCE_HANDLER interface
and implement the HANDLE_GET method
:
method ZIF_RESOURCE_HANDLER~HANDLE_GET.
DATA: ls_param LIKE LINE OF it_params,
ls_from TYPE BAPISFLDST,
ls_to TYPE BAPISFLDST,
ls_date_range TYPE BAPISFLDRA,
lt_date_range TYPE TABLE OF BAPISFLDRA,
lt_flight_list TYPE TABLE OF BAPISFLDAT.
READ TABLE it_params INTO ls_param INDEX 1.
ls_from-airportid = ls_param-value.
READ TABLE it_params INTO ls_param INDEX 2.
ls_to-airportid = ls_param-value.
READ TABLE it_params INTO ls_param INDEX 3.
ls_date_range-sign = 'I'.
ls_date_range-option = 'EQ'.
ls_date_range-low = ls_param-value.
APPEND ls_date_range TO lt_date_range.
CALL FUNCTION 'BAPI_FLIGHT_GETLIST'
EXPORTING
* AIRLINE =
DESTINATION_FROM = ls_from
DESTINATION_TO = ls_to
* MAX_ROWS =
TABLES
DATE_RANGE = lt_date_range
* EXTENSION_IN =
FLIGHT_LIST = lt_flight_list
* EXTENSION_OUT =
* RETURN =
.
IF sy-subrc EQ 0.
CALL TRANSFORMATION ('ID')
SOURCE tab = lt_flight_list
RESULT XML ev_content
OPTIONS xml_header = 'WITHOUT_ENCODING'.
ENDIF.
ev_status_code = ZIF_RESOURCE_HANDLER~gc_status_ok.
ELSE.
ev_status_code = ZIF_RESOURCE_HANDLER~gc_status_gone.
ENDIF.
endmethod.
Then we'll need to add some code to the GET_ROUTING method of the ZCL_RESTFUL_CONTROLLER class :
ls_routing-clnt = sy-mandt.
ls_routing-guid = '003'.
ls_routing-url_info = '/flights/from//to//date/'.
ls_routing-handler_class = 'ZCL_RESOURCE_FLIGHTS'.
APPEND ls_routing TO rt_routing_tab.
There's a bug in the GET_CONTROLLER method so change the
following line of code :
* SHIFT lv_url_info LEFT DELETING LEADING lv_url_part.
REPLACE FIRST OCCURRENCE OF lv_url_part IN lv_url_info WITH SPACE.
Activate everything and use
your browser of choice to navigate to
. You should get the list
of flights that meet the selection criteria in XML format :
!https://weblogs.sdn.sap.com/weblogs/images/251854525/WP71_XML_Response.jpg|height=414|alt=image|widt...!</body>