wp7 - how to guide
TRANSCRIPT
-
7/27/2019 WP7 - How to Guide
1/24
Consuming SAP NetWeaver Gateway
Services from Windows Phone 7
Applications
-
7/27/2019 WP7 - How to Guide
2/24
Copyright/Trademark
Copyright
Copyright 2011 SAP AG. All rights reserved.
SAP Library document classification: PUBLIC
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission
of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of othersoftware vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, Systemz9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF,Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix aretrademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe SystemsIncorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registeredtrademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium,
Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented andimplemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork, and other SAPproducts and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAPAG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence,Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos aretrademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and services mentionedherein as well as their respective logos are trademarks or registered trademarks of Sybase, Inc. Sybase is an SAPcompany.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in thisdocument serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not beliable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services arethose that are set forth in the express warranty statements accompanying such products and services, if any. Nothingherein should be construed as constituting an additional warranty.
-
7/27/2019 WP7 - How to Guide
3/24
Copyright/Trademark
Table of Contents
Consuming SAP NetWeaver Gateway Services on Windows Phone 7 Applications................................. 4
Prerequisites................................................................................................................................................................. 6Building a WP7 Application ........................................................................................................................................ 7
Function Import Example ....................................................................................................................................... 7Read Example ....................................................................................................................................................... 11Create Example..................................................................................................................................................... 12Creation of Request Body for Create Method:.................................................................................................. 15
Appendix 1 - RMTSAMPLEFLIGHT Service Metadata Description ...............................................................16
Appendix 2 Code Snippets ...............................................................................................................................22
Read - Get Carrier by Carrier ID.............................................................................................................................. 22Function Import .......................................................................................................................................................... 23Create - Booking a Flight .......................................................................................................................................... 24
-
7/27/2019 WP7 - How to Guide
4/24
Copyright/Trademark
CONSUMING SAP NETWEAVER GATEWAY SERVICES
FROM WINDOWS PHONE 7 APPLICATIONS
SAP NetWeaver Gateway technology provides a simple way to interact with SAP applications through
variety of devices, environments and platforms based on market standards. The framework enables
development of innovative, people-centric solutions that bring the power of SAP business software into
new experiences, such as: social networking and collaboration environments; mobile and tablet devices;
and rich internet applications. The framework supports rapid innovation while ensuring security, integrity,
management and optimized maintenance of the core SAP systems. Completely flexible, the software offers
connectivity to SAP applications using any programming language or model without the need for SAP
knowledge by taking advantage of REST services and OData/ATOM protocols.
This guide provides information on how to consume SAP NetWeaver Gateway services from Windows
Phone 7 applications based on the following scenario:
The user wants to fly from New York to San Francisco.
He goes online and searches for the different flights available. He enters his search parameters: city of
origin, destination city, departure date, and arrival date (Function Import).
From the SAP NetWeaver Gateway, he receives the information for the option(s) that meet(s) his search
parameters (Get Function).
He can now select the one that suits him the most and book his flight (Create Function).
The links to access the service document and metadata document are provided the in table below.
Service
Document
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/
Metadata
Document
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/
$metadata?$format=xml
Each service URL should contain the following information:
Gateway host
Port
SAP Client no need to specify client if connecting to the default client.
Example:
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT?sap-client=100
To obtain information on the selected service (its properties, function imports, associations, etc.), refer to
Appendix 1, were we show the Metadata description of the RMTSAMPLEFLIGHT service.
To view the code snippets in a format that can be copied into new code, refer toAppendix 2 Code
Snippets.
-
7/27/2019 WP7 - How to Guide
5/24
Copyright/Trademark
The Flight service contains the following collections:
Collection URL
FlightCollection (list of flights) http://:/sap/opu/sdata/
iwfnd/RMTSAMPLEFLIGHT/FlightCollection
CarrierCollection (list of carriers http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection
BookingsCollection (list of Bookings) http://:/sap/opu/sdata/
iwfnd/RMTSAMPLEFLIGHT/BookingCollection
The operation GetAvailableFlights on FlightCollection is used to get a list of flights. The following is the URL
for the same:
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlightsEach collection supports some or all of the operations listed below. The table below provides the list of
operations supported and the methods that each of this operations map to respectively:
Operation Method
Create HTTP POST
Read GET
Update PUT
Delete DELETE
-
7/27/2019 WP7 - How to Guide
6/24
Copyright/Trademark
Prerequisites
The following tools are required for developing a Windows Phone 7 application:
Software Version
SAP NetWeaver Gateway 2.0
.NET .NET Framework 4.0
Microsoft Visual Studio Visual Studio 2010 SP1
Portable Library Tool
(Add-in for Visual Studio)
http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-
e138-410b-ad10-00cb3caf4981/
Windows Phone SDK 7.1 Beta2
http://www.microsoft.com/download/en/details.aspx?displayla
ng=en&id=26648
Silverlight Toolkit http://silverlight.codeplex.com/
Operating System Windows XP, Windows Vista, and Windows 7, and Server 64
Runtime environment .NET 4.0
Contact your system administrator for landscape details to connect to the SAP NetWeaver Gateway system.
Make sure you have performed the following procedures:
Create a new Windows Phone 7 project and select the "Windows Phone 7.1" target for the application.
Add proxies for the relevant service to your WP7 project by selecting Add Service Reference from the
project menu.
http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26648http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26648http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26648http://silverlight.codeplex.com/http://silverlight.codeplex.com/http://silverlight.codeplex.com/http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26648http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26648http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/ -
7/27/2019 WP7 - How to Guide
7/24
Copyright/Trademark
Building a WP7 Application
Function Import Example
To get a list of the available flights, based on filter criteria, trigger the GetAvailableFlights function import
with cityFrom, cityTo, fromDate and toDate parameters. The response will contain a list of flights that meet
the criteria.
Note: For more information on Function Import (also called Service Operation), refer to OData
documentation athttp://www.odata.org/developers/protocols/uri-conventionsunder the Addressing
Service Operations section.
Refer to the code snippet below for details on how to do it from a WP7 application:
1. Declare the DataServiceContext object (in this case RMTSAMPLEFLIGHT) in the scope of the class, since it
is used in more than one method.
privateRMTSAMPLEFLIGHT service;
2. Define an observable collection for flights that you can bind in the Application UI.
privateObservableCollection _Flights;
publicObservableCollection Flights
{
get { return _Flights; }
privateset
{
_Flights = value;
NotifyPropertyChanged("Flights");
}
}
3. Use the following method for executing a Function Import that returns a collection of flights.
privatestaticvoid GetAvailableFlights()
{
4. Connect to the desired service.
string serviceUrl ="http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";
service = newRMTSAMPLEFLIGHT(newUri(serviceUrl));
5. Enter the service credentials.
service.Credentials = newNetworkCredential(username, password);
6. Create the Function Import.
a) Enter the name for the Function Import you want to call.
string functionImportName = "GetAvailableFlights";
b) Set the values for all Function Import parameters and construct the URL.
http://www.odata.org/developers/protocols/uri-conventionshttp://www.odata.org/developers/protocols/uri-conventionshttp://www.odata.org/developers/protocols/uri-conventionshttp://www.odata.org/developers/protocols/uri-conventions -
7/27/2019 WP7 - How to Guide
8/24
Copyright/Trademark
string cityFrom = HttpUtility.UrlEncode("NEW YORK");
string cityTo = HttpUtility.UrlEncode("SAN FRANCISCO");
StringBuilder parameters = newStringBuilder();
parameters.AppendFormat(String.Format("cityfrom={0}&", cityFrom));
parameters.AppendFormat(String.Format("cityto={0}&", cityTo));
parameters.AppendFormat("fromdate=20110105&");
parameters.AppendFormat("todate=20110728");
string relativeUri = functionImportName + "?" + parameters.ToString();
Uri uri = newUri(relativeUri, UriKind.Relative);
c) Execute the asynchronous call to the Function Import and define which method handles the return
from the asynchronous call.
service.BeginExecute(uri,OnRetrievedFlights,service);
7. Handle the return from the asynchronous request.
privatevoid OnRetrievedFlights(IAsyncResult result)
{ // Use the Dispatcher to ensure that the
// asynchronous call returns in the correct thread.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
try{
// Get the context from the result.
service = result.AsyncState asRMTSAMPLEFLIGHT;
// Get the end result of the load operation.
var response = service.EndExecute(result);
// Add each flight in the response to the Flights Observable Collection
foreach (var flight in response){
this.Flights.Add(flight);
}
}
catch (Exception ex)
{
// Handle exception
}}
);
}
-
7/27/2019 WP7 - How to Guide
9/24
Copyright/Trademark
Response
-http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection
FlightCollection2011-09-27T06:32:42Z
-
--
AA00172011-01-05T00:00:00889.00
USD747-400385367
185742.7331222121
-USnew yorkJFKUSSAN FRANCISCOSFO361PT11H00M00SPT14H01M00S2574.0000
SMI0
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection(carrid='AA',connid='0017',fldate='20110105')
Flight2011-09-27T06:32:42Z
-
-
-AA
00172011-03-16T00:00:00422.94
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728 -
7/27/2019 WP7 - How to Guide
10/24
Copyright/Trademark
USD747-400
385371192129.2231302120
-USnew yorkJFKUSSAN FRANCISCOSFO361PT11H00M00S
PT14H01M00S2574.0000SMI0
http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection(carrid='AA',conn
id='0017',fldate='20110316')
Flight2011-09-27T06:32:42Z
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/GetAvailableFlights?cityfrom=NEW%20YORK&cityto=SAN%20FRANCISCO&fromdate=20110105&todate=20110728 -
7/27/2019 WP7 - How to Guide
11/24
Copyright/Trademark
Read Example
To read the carrier details, you must call the CarrierCollection using the Carrier ID parameter.
Refer to the code snippet below for details on how to do it from a WP7 application:
1. Declare the DataServiceContext object (in this case RMTSAMPLEFLIGHT) in the scope of the class, since it
is used in more than one method.
privateRMTSAMPLEFLIGHT service;
2. Define an observable collection for Carriers that you can bind in the Application UI.
privateObservableCollection _Carriers;
publicObservableCollection Carriers
{
get { return _Carriers; }
privateset
{
_Carriers = value;
NotifyPropertyChanged("Carriers");}
}
1. Use the following method for getting Carrier information from the carrierId parameter.
privatestaticvoid GetCarrierByID()
{
2. Specify the carrierId parameter for which we want to receive information.
string carrierId = "AA"; //American Airlines
3. Connect to the desired service.
string serviceUrl =
"http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";
service = newRMTSAMPLEFLIGHT(newUri(serviceUrl));
4. Enter the service credentials.
service.Credentials = newNetworkCredential(username, password);
5. To retrieve the carrier with matching carrier id, create the query below.
var carrier = (fromCarrier c in service.CarrierCollection
where c.carrid == carrierId
select c;
6. Define a delegate that will handle the return from the asynchronous execution of the query.
collection.LoadCompleted += (sender, e) =>
{
if (e.Error == null) // In case of successful loading
{
// get the collection that contains all loaded Carriers
var _binding = sender asDataServiceCollection;
// Load all pages before binding.
if (_binding.Continuation != null)
{
_binding.LoadNextPartialSetAsync();
}
else// Load is completed - ready to be bound
-
7/27/2019 WP7 - How to Guide
12/24
Copyright/Trademark
{
this.Carriers = _binding;
}
}
else// In case of failure to load
{
// Handle error
}};
7. Execute the asynchronous request to load the collection with items that match the query.
collection.LoadAsync(query);
Response
-
-AAAmerican AirlinesUSDhttp://www.aa.com
:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')
Carrier2011-09-27T10:00:38Z
Create Example
To book a flight, trigger an HTTP POST method on the Booking Collection (with the Booking details in the
request body). Check for the HTTP response code. If the response code is 201, then the HTTP-POST is
successful. The response contains the newly created Booking ID in the bookidfield, as well as the entire
information that was part of the request body.
Refer to the code snippet below for details on how to invoke a create request from a WP7 application:
1. Declare the DataServiceContext object (in this case RMTSAMPLEFLIGHT) in the scope of the class, since it
is used in more than one method.
privateRMTSAMPLEFLIGHT service;
2. Use the following method for booking a flight.
privatestaticvoid CreateFlightBooking()
{
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA')http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(carrid='AA') -
7/27/2019 WP7 - How to Guide
13/24
Copyright/Trademark
3. Create the new Booking item.
Booking booking = newBooking()
{
carrid = "AA",
connid = "0017",
fldate = Convert.ToDateTime("2011-12-21T00:00:00"),
bookid = String.Empty,
CUSTOMID = "00004617",
CUSTTYPE = "P",
WUNIT = "KG",
LUGGWEIGHT = (Decimal)14.4000,
CLASS = "Y",
FORCURAM = (Decimal)879.82,
FORCURKEY = "USD",
LOCCURAM = (Decimal)803.58,
LOCCURKEY = "USD",
ORDER_DATE = Convert.ToDateTime("2011-05-22T00:00:00"),
COUNTER = "00000000",
AGENCYNUM = "00000325",
PASSNAME = "Joe Smith",
PASSFORM = "1234567",
PASSBIRTH = Convert.ToDateTime("1990-10-10")
};
4. Connect to the desired service.
string serviceUrl =
"http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";
service = new RMTSAMPLEFLIGHT(newUri(serviceUrl));
5. Enter the service credentials.
service.Credentials = newNetworkCredential(username, password);
6. Add request headers that will be added when the request to the service is executed. Without the
headers, the HTTP POST request will fail.
service.SendingRequest += (sender, e) =>{
e.RequestHeaders["X-Requested-With"] = "XMLHttpRequest";
};
7. Add the new Booking item to the service.
Note: The changes are made only in the client side the service is not aware of these changes.
service.AddToBookingCollection(booking);
-
7/27/2019 WP7 - How to Guide
14/24
Copyright/Trademark
8. Save all changes made to the service asynchronously and declare the method that handles the return
from the asynchronous save operation
service.BeginSaveChanges(OnSaveCompleted, service);
9. Define the method that handles the return from the asynchronous Save operation
privatevoid OnSaveCompleted(IAsyncResult result){
// Use the Dispatcher to ensure that the
// asynchronous call returns in the correct thread.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
try
{
// Get the context from the result.
service = result.AsyncState asRMTSAMPLEFLIGHT;
// Get the end result of the load operation.
DataServiceResponse response = service.EndSaveChanges(result);
int i = 0;
foreach (ChangeOperationResponse change in response){
if (change.Error != null){
var changeResult = string.Format("Change {0} error: {1}\n", i,
change.Error.Message);MessageBox.Show(changeResult);
}
elseif (change.StatusCode != 201)
{
// Handle error
}
else
{// Handle successful save
}
i++;
}
}
catch (Exception ex)
{
// Handle Exception
}
}
);
}
-
7/27/2019 WP7 - How to Guide
15/24
Copyright/Trademark
Creation of Request Body for Create Method:
The request body can be easily created by looking at the tags in the collections metadata. For example, the
metadata for Booking Collection provides information about the various fields (tags) that are needed for
creating a booking:
-
7/27/2019 WP7 - How to Guide
16/24
Copyright/Trademark
Appendix 1 - RMTSAMPLEFLIGHT Service Metadata
Description
-
7/27/2019 WP7 - How to Guide
17/24
Copyright/Trademark
-
7/27/2019 WP7 - How to Guide
18/24
Copyright/Trademark
-
7/27/2019 WP7 - How to Guide
19/24
Copyright/Trademark
-
7/27/2019 WP7 - How to Guide
20/24
Copyright/Trademark
Airline
Flight Number
Date
-
7/27/2019 WP7 - How to Guide
21/24
Copyright/Trademark
Date
Date
Depart.city
Arrival city
-
7/27/2019 WP7 - How to Guide
22/24
Copyright/Trademark
Appendix 2Code Snippets
Read - Get Carrier by Carrier ID
///
/// Method for getting Carrier information by its carrierId///
privatestaticvoid GetCarrierByID()
{
// Specify the carrierId to search for
string carrierId = "AA"; //American Airlines
/******************************************************************************* Connection to the service
******************************************************************************/
string serviceUrl ="http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";
RMTSAMPLEFLIGHT.RMTSAMPLEFLIGHT service = new RMTSAMPLEFLIGHT.RMTSAMPLEFLIGHT(newUri(serviceUrl));
service.Credentials = newNetworkCredential(username, password);
/******************************************************************************
* Execute the Query to the service to retrieve the carrier
******************************************************************************/
var carrier = (fromCarrier c in service.CarrierCollection
where c.carrid == carrierId
select c).FirstOrDefault();
/******************************************************************************
* Using the returned value******************************************************************************/
Console.WriteLine(String.Format("Carrier ID = {0}",carrier.carrid));
Console.WriteLine(String.Format("Carrier Name = {0}",carrier.CARRNAME));
Console.WriteLine(String.Format("Carrier Code = {0}",carrier.CURRCODE));
Console.WriteLine(String.Format("Carrier URL = {0}",carrier.URL));
}
-
7/27/2019 WP7 - How to Guide
23/24
-
7/27/2019 WP7 - How to Guide
24/24
Copyright/Trademark
Create - Booking a Flight
///
/// Method for creating a new flight booking.
///
privatestaticvoid CreateFlightBooking()
{
/******************************************************************************
* Creating the new Booking item
******************************************************************************/
Booking booking = newBooking(){
carrid = "AA",
connid = "0017",
fldate = "2011-07-27T00:00:00",
bookid = String.Empty,
CUSTOMID = "00004617",
CUSTTYPE = "P",WUNIT = "KG",
LUGGWEIGHT = (Decimal)14.4000,
CLASS = "Y",FORCURAM = (Decimal)879.82,
FORCURKEY = "USD",
LOCCURAM = (Decimal)803.58,
LOCCURKEY = "USD",
ORDER_DATE = "2011-05-22T00:00:00",
COUNTER = "00000000",
AGENCYNUM = "00000325",PASSNAME = "Joe Smith",
PASSFORM = "1234567",
PASSBIRTH = "1990-10-10T00:00:00",
};
/******************************************************************************* Connection to the service
******************************************************************************/
string serviceUrl =
"http://:/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/";
RMTSAMPLEFLIGHT.RMTSAMPLEFLIGHT
service = new RMTSAMPLEFLIGHT.RMTSAMPLEFLIGHT(newUri(serviceUrl));
service.Credentials = newNetworkCredential(username, password);
/******************************************************************************
* Add the new booking to the service * (changes are made only in the client side)
******************************************************************************/
service.AddToBookingCollection(booking);
/******************************************************************************* Save all changes done to the service * (executes the call to the service)
******************************************************************************/
try
{
service.SaveChanges();
}
catch (Exception ex){
Console.Write(ex.Message);
}}