Beruflich Dokumente
Kultur Dokumente
Agenda
Web Requests
WebClient HttpWebRequest Consuming Web Service
Web Requests
WP7 uses the same Web request API as normal .NET
Only the asynchronous request methods available
Web Requests
WebClient
The WebClient does not support concurrent calls
You have to manage to wait for the completion of the previous call before starting another one
Web Requests
WebClient
How to use it the simplest way:
Web Requests
WebClient
How to use it beter way:
Web Requests
HttpWebRequest
Basic scenario:
Create an instance of the HttpWebRequest If you have to post something get the request stream Then write posted data to the request stream Get the response (that is actually what starts the call) Get the response stream Read returned data from response stream Close all thing
Web Requests
HttpWebRequest How to use it the simplest way:
Web Requests
HttpWebRequest How to use it beter way:
Web Requests
Consuming Web Service
The WebClient and HttpWebRequest are both complete and easy to use, the problem is that their usage is for sure heavy, because you need to rely on your own protocol made for example of XML files.
The process of serializing and deserializing can become very annoying. The real answer to this problem are the Web Services - something that is based on a known protocol (built on top of HTTP) and makes easy the process of sharing data between client and server, hiding transport and serialization problems.
Web Requests
Consuming Web Service
Working with Web Services you have to be aware of three things that uniquely define the Web Service you want to consume: Address, Binding and Contract.
Address - says where the service is located, in the form of a Uri Binding - describes how the client and server will speak each other. Serialization and deserialization matter is part of the binding but also the transport: HTTP, HTTPS, and so on. Contract - the most important part, that describes what the service can do.
In WCF, a contract is an interface with a bunch of methods - usually called Operations - and each one do something with some kind of input and output.
Web Requests
Consuming Web Service
Once you have the Address of the service you have to consume, the first thing you have to do is creating a Proxy. The proxy is a client side class that implements the Contract of the service and hides to the developer the presimageence of a Web Service.
What it happens is that you call a method on the local class and the proxy take care of serialize request, making the network call, reading the response and deserializes it.
Location services
Windows Phone uses three technologies for finding your location: GPS, WiFi based location, and Cell Tower based location (triangulation).
Location services
GPS technology relies on satellites in orbit and the phone's ability to receive signals from at least three of these satellites.
The satellites are transmitting all the time from synchronized clocks. But because of the satellites being different distances from the phone the time received from the satellites will be slightly different, a user's position can be calulated from these time differences.
Cell Tower based location and WiFi based location are similar to GPS in how they work.
When you use either one of these the phone will try to get the identifiers for near by WiFi access points and cell towers. The identifier is sent to a Microsoft service which keeps records of the general area in which those WiFi access points or cell towers have been seen and returns that information to the device.
Location services
Each one of these location technologies differs in the accuracy of the location that it provides.
GPS is the most accurate with the margin of error being around 10 meters in favourable conditions. The next most precise location technology is WiFi based location. WiFi access points don't transmit nearly as far as cell towers. Cell tower based location is the least precise.
Generally speaking the more precise location technology (GPS) also has a more significant impact on battery life.
Location services
Things to Remember
Request the Location Services capability in your WMAppManifest.xml
Ask the user for permission to get their location Be prepared for the possibility of location services being disabled on the phone Don't transmit the user's location to any service without their permission Only use high accuracy location when needed Turn off location services when it is nolonger needed Nokia Places API for Windows Phone
Accelerometer
The accelerometer is a sensor in the Windows Phone device that measures the acceleration on 3 axes (X, Y, Z), relative to freefall.
Accelerometer
In addition to a timestamp, the values are expressed in Gforces (1G = 9.81 m/s2).
It this means is that if the phone is lying face-up on a perfectly flat surface, the Z axis would read 1.0, and the other two axes would read 0.
Accelerometer
The emulator emulates accelerometer data by Accelerometer tab in Additional tools window.
Feature introduced in Mango release. By default the emulator assumes it is standing in portrait position, lined up on a flat surface.
Compass
In traditional terms, a compass is used to determine the direction of the Earths magnetic north pole. Mobile phones are using element called magnetometer.
It can still determine the direction of magnetic north, but it can also determine rotation of the device relative to magnetic north. In addition, it is also capable of detecting magnetic fields around the device (which often interfere with those other calculations). The MagneticHeading is the heading, in degrees, measured clockwise from the Earths magnetic north. The TrueHeading is the heading, in degrees, measured clockwise from the Earths geographic north. The X, Y, and Z values that you retrieve from API are actually measured in microteslas, which are a unit of magnetic field strength.
Gyroscope
According to Wikipedia, a gyroscope is a device for measuring or maintaining orientation. It has the ability to spin on three axes, the X, Y, and Z axis
While the Accelerometer measures acceleration, the Gyroscope measures rotational velocity. The data you receive measures the rotational velocity of the device in radians per second. This means that you can more accurately and smoothly measure the current orientation of the device.
Q&A
??