380 likes | 567 Views
Building a Picture Frame, Part 3: Connect a Windows Embedded CE Device to Web Services. Douglas Boling President Boling Consulting Inc. WEM202. Speaker. Douglas Boling Author – Programming Microsoft Windows CE 4th Edition
E N D
Building a Picture Frame, Part 3: Connect a Windows Embedded CE Device to Web Services Douglas Boling President Boling Consulting Inc. WEM202
Speaker • Douglas Boling • Author – Programming Microsoft Windows CE • 4th Edition • Trainer – Classes on Windows CE App Development Windows CE OAL Development .NET Compact Framework • Consultant – 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 Services • What is a web service • Desktop/Server support • Tools 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 sites • Using the web w/o “screen scraping” • RPC protocol using port 80 • Uses “SOAP” • Simple Object Access Protocol • All data transmitted as strings
Desktop/Server Support • Server side • Microsoft support via ASP • Simple to implement with ASP .NET • Client side • Simple to implement via .NET framework • Native clients implemented with ATL
Tools To write Web Service Clients • Visual Studio provides support • Server side • Client side • .NET commonly used for both sides • Native implementations can work • Client – 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
Writing a Web Service • Simple, with ASP.NET • First example… • Add two numbers • VS 2005/2008 caution • Defaults to Local Development Server • Services can’t be seen by CE devices/emulators • IIS configuration difficult!
Agenda • Introduction to Web Services • Implementing a Web Service Client • Native • Managed • 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
demo Web Services Douglas Boling President Boling Consulting Inc.
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.Com • Part 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 available • We’re going to write a trivial one here
Example RSS XML Feed <?xmlversion="1.0"encoding="utf-8"?> <rssversion="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> <guidisPermaLink="true"> http://0mxaeg.blu.live/…/DSCN0360.JPG</guid>
Example RSS XML Item (2) <description><![CDATA[ <imgsrc= "http://0mxaeg.blu.live/…/DSCN0360.JPG“ /><br/>]]></description> <pubDate>Mon, 30 Mar 2009 17:30:42 -0700</pubDate> <enclosuretype="image/jpeg“ url="http://0mxaeg.blu.live/…/DSCN0360.JPG" /> <media:contenttype="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 Frame • Native • Managed
Tasks of Native Application • Connect to RSS feed • Download XML describing feed • Parse XML • Download images
Connecting UsingWinINet • WinINet library provides higher level access to web • APIs for • Initialize the library • Connect to server • Download file
Initializing WinINet • To initializeWinINet call InternetOpen • Parameters: • Agent String to indicate client type • Access type Indicates proxy or direct connect • Proxy Name Name of proxy server • Flags
Connecting to a Server • To connect to a server, use InternetConnect • Parameters: • lpszServerNameName of server • nServerPort Port to connect • lpszUserNameOptional user name • lpszPasswordOptional password • dwService HTTP or FTP • A few others…
Reading A File • Use the following functions • HttpOpenRequest • HttpAddRequestHeaders • HttpSendRequest • If successful, loop on • HttpQueryInfo • InternetQueryDataAvailable • InternetReadFile
demo Native Picture Frame RSS Reader Code Douglas Boling President Boling Consulting Inc.
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(); StreamReadersr = new StreamReader(response.GetResponseStream()); stringstrXMLFeed = sr.ReadToEnd(); response.Close(); // Write the string into a file StreamWritersw = newStreamWriter(strXMLFile); sw.Write(strXMLFeed); sw.Close();
Parse The Feed XmlTextReader reader = newXmlTextReader(strFilename); while (reader.Read()) { switch (reader.NodeType) { caseXmlNodeType.Element: if (reader.Name == "enclosure“) { if (reader.AttributeCount > 0) { strURL = reader.GetAttribute("url"); if (null != strURL) ar.Add(strURL); } break; } }
demo Managed Frame RSS Reader Code Douglas Boling President Boling Consulting Inc.
Summary • Web services client support available in Windows Embedded CE • Managed much easier than native • RSS feeds aren’t that difficult • Again… Managed much easier than native
question & answer dboling@bolingconsulting.com
Windows Embedded Resources Website: www.windowsembedded.com Social Channels: blogs.msdn.com/mikehall blogs.msdn.com/obloch Technical Resources: http://msdn.microsoft.com/embedded Tools evaluations: www.windowsembedded.com/downloads
Resources • www.microsoft.com/teched Sessions On-Demand & Community • www.microsoft.com/learning • Microsoft Certification & Training Resources • http://microsoft.com/technet • Resources for IT Professionals • http://microsoft.com/msdn Resources for Developers www.microsoft.com/learning Microsoft Certification and Training Resources
© 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.