Skip to Content

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.

image

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|width=522|src=https://weblogs.sdn.sap.com/weblogs/images/251854525/WP71_XML_Response.jpg|border=0!</body>

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Guillaume GARCIA
    Hi Pierre,

    Android, Sybase Unwired Platform and now Windows Phone 7… looks like your mobility knowledge has no limit  🙂
    Looking forward to see what will be the next plaform you will deal with!

    Best regards,
    Guillaume

    (0) 
    1. Pierre Dominique Post author
      Hi Guillaume,

      I’m just trying to evaluate the different mobile platforms and see what they have to offer. And so far Windows Phone 7 is one of the most promising. 🙂

      Regards,
      Pierre

      (0) 
  2. Simon Kemp
    Hi,

    Thanks for taking the time to blog on this topic. I have also been looking at Windows Phone 7 and recognize great potential esp. if MS do some really great stuff for the enterprise with integration into Office and SharePoint.

    I was just wondering what your thoughts were when it comes to having to write REST based web services (or could you have used SOAP?). Most of the Enterprise Services that SAP delivers are SOAP based right? My understanding is that this is quite slow and cumbersome… is that your experience?

    Does the SYBASE unwired platform remove this need? In that scenario would the phone connect to the SYBASE middleware?

    Thanks,
    Simon

    (0) 
    1. Pierre Dominique Post author
      Hi Simon,

      In my opinion SOAP is too verbose for mobile applications. I’m not even talking about SAP ES, these are way too complex to be consumed by a mobile application…

      A mobile platform such as SUP would completely remove this need because Sybase provides their own client API. The mobile application uses this API to communicate with the Unwired server, it does not connect to the backend. However SUP does not support Windows Phone 7 (yet).

      If you really need to develop a WP7 application today, you could use REST Web Services using the JSON format for maximum efficiency. This format is used by SUP for communications between the mobile client and the Unwired server.

      Regards,
      Pierre

      (0) 
  3. Stephan Becker

    Hi Pierre,

    the first part of your excellent blog is missing links and pictures, can you maybe provide a link to a full version of the text?

    Cheers,

    Stephan

    (0) 
    1. Pierre Dominique Post author

      Hi Stephan,

      I think the issue is related to the migration to the new SCN. The layout is messed up and some images are missing. I’ll re-create the blog if I find the time to do it.

      Cheers,

      Pierre

      (0) 
      1. Stephan Becker

        Hi Pierre, thanks for the reply.

        The example is understandable as is, the only thing really missing is the actual URL to test at the end.

        Also, a hint or two on how to debug the SAP part would be great, i.e. can I specify some input parameter for the method so that the URL retrieval works?! I tried to comment out the URL retrieval and debug/replace in the URL, but then the REGEX part doesn’t work for some reason..

        Cheers, Stephan

        (0) 

Leave a Reply