Douglas Boling President Boling Consulting Inc. WEM202.

38

Transcript of Douglas Boling President Boling Consulting Inc. WEM202.

Page 1: Douglas Boling President Boling Consulting Inc. WEM202.
Page 2: Douglas Boling President Boling Consulting Inc. WEM202.

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

PresidentBoling Consulting Inc.WEM202

Page 3: Douglas Boling President Boling 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

Page 4: Douglas Boling President Boling Consulting Inc. WEM202.

Agenda

Introduction to Web Services

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture Frame

Page 5: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 6: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 7: Douglas Boling President Boling Consulting Inc. WEM202.

Server sideMicrosoft support via ASPSimple to implement with ASP .NET

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

Desktop/Server Support

Page 8: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 9: Douglas Boling President Boling Consulting Inc. WEM202.

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!

Page 10: Douglas Boling President Boling Consulting Inc. WEM202.

Agenda

Introduction to Web Services

Implementing a Web Service ClientNativeManaged

Understanding RSS Feeds

Connecting the Picture Frame

Page 11: Douglas Boling President Boling Consulting Inc. WEM202.

Native Web Service Client

Start with a simple device application

Add ATL support

Allow single threads in MTA

Increase stack size

Page 12: Douglas Boling President Boling Consulting Inc. WEM202.

Native Web Service Client

Add Web Reference

Include webref.h in stdafx.h

Create web client class

Call method

Page 13: Douglas Boling President Boling Consulting Inc. WEM202.

A Managed Web Service Client

Simple .NET Windows Forms App

Add web reference

“New up” the web reference object

Call methods

Page 14: Douglas Boling President Boling Consulting Inc. WEM202.

Web ServicesDouglas BolingPresidentBoling Consulting Inc.

demo

Page 15: Douglas Boling President Boling Consulting Inc. WEM202.

Agenda

Introduction to Web Services

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture Frame

Page 16: Douglas Boling President Boling Consulting Inc. WEM202.

Project

Create a picture frame that connects to web

Change of plans…Use RSS instead of Web Service

Page 17: Douglas Boling President Boling Consulting Inc. WEM202.

New Project

Web based pictures at FrameIt.ComPart of Windows Live Services

Use RSS feed to query pictures

Download and display pictures

Page 18: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 19: Douglas Boling President Boling Consulting Inc. WEM202.

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>

Page 20: Douglas Boling President Boling Consulting Inc. WEM202.

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>

Page 21: Douglas Boling President Boling Consulting Inc. WEM202.

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>

Page 22: Douglas Boling President Boling Consulting Inc. WEM202.

Agenda

Introduction to Web Services

Implementing a Web Service Client

Understanding RSS Feeds

Connecting the Picture FrameNativeManaged

Page 23: Douglas Boling President Boling Consulting Inc. WEM202.

Tasks of Native Application

Connect to RSS feed

Download XML describing feed

Parse XML

Download images

Page 24: Douglas Boling President Boling Consulting Inc. WEM202.

Connecting Using WinINet

WinINet library provides higher level access to web

APIs for Initialize the libraryConnect to serverDownload file

Page 25: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 26: Douglas Boling President Boling Consulting Inc. WEM202.

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…

Page 27: Douglas Boling President Boling Consulting Inc. WEM202.

Reading A File

Use the following functionsHttpOpenRequestHttpAddRequestHeadersHttpSendRequest

If successful, loop onHttpQueryInfoInternetQueryDataAvailableInternetReadFile

Page 28: Douglas Boling President Boling Consulting Inc. WEM202.

Native Picture Frame RSS Reader CodeDouglas BolingPresidentBoling Consulting Inc.

demo

Page 29: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 30: Douglas Boling President Boling Consulting Inc. WEM202.

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(); 

Page 31: Douglas Boling President Boling Consulting Inc. WEM202.

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; } }

Page 32: Douglas Boling President Boling Consulting Inc. WEM202.

Managed Frame RSS Reader CodeDouglas BolingPresidentBoling Consulting Inc.

demo

Page 33: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 34: Douglas Boling President Boling Consulting Inc. WEM202.

question & [email protected]

Page 35: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 36: Douglas Boling President Boling Consulting Inc. WEM202.

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

Page 37: Douglas Boling President Boling Consulting Inc. WEM202.

Complete an evaluation on CommNet and enter to win!

Page 38: Douglas Boling President Boling Consulting Inc. WEM202.

© 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.