Douglas Boling President Boling Consulting Inc. WEM202

Preview:

Citation preview

Building a Picture Frame, Part 3: Connect a Windows Embedded CE Device to Web Services Douglas Boling

PresidentBoling Consulting Inc.WEM202

Speaker

Douglas Boling Author – Programming Microsoft Windows CE

4th EditionTrainer – Classes on Windows CE App DevelopmentWindows CE OAL Development.NET Compact FrameworkConsultant – Work with companies to help their Windows CE application and platform development efforts

Agenda

Introduction to Web Services

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture Frame

Agenda

Introduction to Web ServicesWhat is a web serviceDesktop/Server supportTools to write web service clients

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture Frame

What is a Web Service?

Web services are ‘programmatic’ web sitesUsing the web w/o “screen scraping”RPC protocol using port 80

Uses “SOAP” Simple Object Access ProtocolAll data transmitted as strings

Server sideMicrosoft support via ASPSimple to implement with ASP .NET

Client sideSimple to implement via .NET frameworkNative clients implemented with ATL

Desktop/Server Support

Visual Studio provides supportServer sideClient side

.NET commonly used for both sides

Native implementations can workClient – ATL sample today Server – Mike Hall example on CE

http://blogs.msdn.com/mikehall/archive/2007/10/10/building-xml-web-services-for-windows-embedded-ce-6-0.aspx

Tools To write Web Service Clients

Writing a Web Service

Simple, with ASP.NET

First example…Add two numbers

VS 2005/2008 cautionDefaults to Local Development Server

Services can’t be seen by CE devices/emulatorsIIS configuration difficult!

Agenda

Introduction to Web Services

Implementing a Web Service ClientNativeManaged

Understanding RSS Feeds

Connecting the Picture Frame

Native Web Service Client

Start with a simple device application

Add ATL support

Allow single threads in MTA

Increase stack size

Native Web Service Client

Add Web Reference

Include webref.h in stdafx.h

Create web client class

Call method

A Managed Web Service Client

Simple .NET Windows Forms App

Add web reference

“New up” the web reference object

Call methods

Web ServicesDouglas BolingPresidentBoling Consulting Inc.

demo

Agenda

Introduction to Web Services

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture Frame

Project

Create a picture frame that connects to web

Change of plans…Use RSS instead of Web Service

New Project

Web based pictures at FrameIt.ComPart of Windows Live Services

Use RSS feed to query pictures

Download and display pictures

RSS – “Really Simple Syndication”

Web feed format for frequently updated content

XML document describes feed content

Many readers availableWe’re going to write a trivial one here

Example RSS XML Feed

<?xml version="1.0" encoding="utf-8"?><rss version="2.0“ xmlns:frameit="http://www.frameit.live.com/firss/" xmlns:media="http://search.yahoo.com/mrss/"> <channel> <ttl>287</ttl> <title>DemoCollection</title> <link>http://frameit.live.com</link> <generator>http://frameit.live.com</generator> <lastBuildDate>Tue, 12 May 2009 13:14:49 -0700 </lastBuildDate> <pubDate>Tue, 12 May 2009 14:27:19 -0700</pubDate> <description></description>

<item>…</item> <item>…</item> <item>…</item></channel>

Example RSS XML Item

<item> <frameit:sourceIcon>xxxxx</frameit:sourceIcon>

<frameit:sourceCategory>Custom</frameit:sourceCategory>

<frameit:sourceName>Windows Live Photos </frameit:sourceName>

<title>Paris</title>

<link>http://0mxaeg.blu.live/…/DSCN0360.JPG</link>

<category>Paris</category>

<guid isPermaLink="true"> http://0mxaeg.blu.live/…/DSCN0360.JPG</guid>

Example RSS XML Item (2)

<description><![CDATA[ <img src= "http://0mxaeg.blu.live/…/DSCN0360.JPG“ /><br/>]]></description>

<pubDate>Mon, 30 Mar 2009 17:30:42 -0700</pubDate>

<enclosure type="image/jpeg“ url="http://0mxaeg.blu.live/…/DSCN0360.JPG" />

<media:content type="image/jpeg" url="http://0mxaeg.blu.live/…/DSCN0360.JPG" />

</item>

Agenda

Introduction to Web Services

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture FrameNativeManaged

Tasks of Native Application

Connect to RSS feed

Download XML describing feed

Parse XML

Download images

Connecting Using WinINet

WinINet library provides higher level access to web

APIs for Initialize the libraryConnect to serverDownload file

Initializing WinINet

To initialize WinINet call InternetOpen

Parameters:Agent String to indicate client typeAccess type Indicates proxy or direct connectProxy Name Name of proxy serverFlags

Connecting to a Server

To connect to a server, use InternetConnect

Parameters:lpszServerName Name of servernServerPort Port to connectlpszUserName Optional user namelpszPassword Optional passworddwService HTTP or FTPA few others…

Reading A File

Use the following functionsHttpOpenRequestHttpAddRequestHeadersHttpSendRequest

If successful, loop onHttpQueryInfoInternetQueryDataAvailableInternetReadFile

Native Picture Frame RSS Reader CodeDouglas BolingPresidentBoling Consulting Inc.

demo

Picture Frame in Managed Code

Managed code much simpler than native

Use WebRequest class to read data

Use XMLReader to parse the RSS XML

Use PictureBox to display image

Download A File

// Compose the request WebRequest request=WebRequest.Create ("http://parisfeed.frameit.com");

WebResponse response = request.GetResponse();

StreamReader sr = new StreamReader(response.GetResponseStream());

string strXMLFeed = sr.ReadToEnd(); response.Close();  // Write the string into a file StreamWriter sw = new StreamWriter(strXMLFile); sw.Write(strXMLFeed); sw.Close(); 

Parse The Feed

XmlTextReader reader = new XmlTextReader(strFilename);

while (reader.Read()) {

switch (reader.NodeType) {

case XmlNodeType.Element:

if (reader.Name == "enclosure“) {

if (reader.AttributeCount > 0) {

strURL = reader.GetAttribute("url");

if (null != strURL) ar.Add(strURL); } break; } }

Managed Frame RSS Reader CodeDouglas BolingPresidentBoling Consulting Inc.

demo

Summary

Web services client support available in Windows Embedded CE

Managed much easier than native

RSS feeds aren’t that difficultAgain… Managed much easier than native

question & answerdboling@bolingconsulting.com

Windows Embedded Resources

Website: www.windowsembedded.com

Social Channels: blogs.msdn.com/mikehallblogs.msdn.com/obloch

Technical Resources: http://msdn.microsoft.com/embedded

Tools evaluations: www.windowsembedded.com/downloads

www.microsoft.com/teched

Sessions On-Demand & Community

http://microsoft.com/technet

Resources for IT Professionals

http://microsoft.com/msdn

Resources for Developers

www.microsoft.com/learningMicrosoft Certification and Training Resources

www.microsoft.com/learning

Microsoft Certification & Training Resources

Resources

Complete an evaluation on CommNet and enter to win!

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Recommended