DEVBUZZ Homepage SmartPhone (SP) and WebService Enhancements (WSE) with .NETcf
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | .NET Compact Framework

SmartPhone (SP) and WebService Enhancements (WSE) with .NETcf
Written by casey chesnut  [author's bio]  [read 46807 times]
Edited by Derek

Download the code   Discuss this article   .NET Compact Framework   

Page 1  Page 2  Page 3  Page 4 

Introduction

So i had taken my 1st cut at WSE from the Compact Framework (.NETcf) many months ago ... (/cfWSE). Since then, i have gotten to do a lot more Web Service (WS) work using the .NETcf. So I felt I was ready for a 2nd attempt to raise the bar ... although this article is really the 3rd in a long running series. I could not continue the /cfWSE article because .NETcf was lacking the System.Security.Cryptography namespace; so that is why I wrote the follow up /spCrypt article. Now I can continue where I left off. My motivation is 2-fold: (1) because WSE does not exist for .NETcf. (2) give me an excuse to learn some more of the Global Xml Architecture (GXA) specifications. This time, client-side development will be with .NETcf using the SP 2003 emulator. Server-side will mostly use the WSE 2.0 implementation (currently a tech preview), along with some of the WSE 1.0 sample web services.

 

SmartPhone

Developed this with the SmartPhone 2003 emulator. 2003 is important, because SP 2002 does not support .NETcf. Also, 2003 has .NETcf with SP1 in ROM. Pocket PC 2003 and Pocket PC Phone Edition 2003 do not have SP1 in ROM, so you could get unexpected behavior. In general though, this code should work on any device that can run the .NETcf. You must also take into account what level of cryptography and algorithms the device / emulator provides (below).

WSE1

WSE has been released and supported by MS for a while. The WS specs it supports are WS-Addressing, DIME, and WS-Security.

WSE2

This is the latest release of WSE that has been a tech preview for a while. It had some breaking changes between it and version 1. One such change was moving to WS-Addressing instead of WS-Routing. It still supports DIME and WS-Security. It also adds support for WS-Trust, WS-Policy and Ws-SecureConversation.

Service Pack 1 (SP1) Rant

For SmartPhone, .NETcf and SP1 are in the ROM! For Pocket PC 2003, .NETcf is in ROM, but not SP1 ... so install it. The problem is the download is just a bunch of zip files, that you have to manually copy around. It explicitly states no new interface changes, but there are some methods that I want to overload now which just became available in SP1; i can deploy the runtime to support them but I cant use VS .NET to build to that. To get VS .NET to build with that overload for CE / PPC, I have to unzip the files that were deployed and then manually rename those files to compile against, or build against an assembly meant for SP (see below). My hope is that .NETcf SP installation will integrate with VS .NET in the future.

GetWebRequest / GetWebResponse

These are the methods on HttpWebClientProtocol that can now be overridden with SP1. This is useful to set HttpHeaders, KeepAlive, and such on the underlying HttpWebRequest and HttpWebResponse used by the autogenerated web reference. For a SP project, you can to it right off the bat. For CE or PPC you have to update the System.Web.Services.dll that VS .NET builds against. What I had to do was copy the assembly that SmartPhone builds against into the CE directory, and then I could override that method on PPC and CE apps as well. You also have to make sure (at least) SP1 is on the emulator or device that you deploy to.

SP - C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\
	v1.0.5000\Windows CE\Smartphone\System.Web.Services.dll
CE / PPC - C:\Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\
	v1.0.5000\Windows CE\System.Web.Services.dll

Session

ASP.NET handles session by using cookies. On the full .NET framework (.NETfx) you can access the CookieCollection to add/remove cookies, but not on .NETcf. So if you wanted to do stateful WS calls your options were cookieless sessions (required WS change), or handle all the SoapMessaging by using the lower level HttpWebRequest/Response classes. By hooking GetWebRequest/Response, you can add the proper cookie headers directly to the HttpWebRequest without changing the service, and still have the convenience of using a web reference proxy. A better way would be per keith ba's WS book, in which Session information is passed using a SoapHeader, and it is not reliant upon a protocol. I do not know of a specification that exists for this?

Service Pack 2 (SP2) Rant

Same as above for SP1, plus you dont get an update for SmartPhone. SP2 has some Web Service fixes and performance improvements... which I obviously want. My hope is that SP2 fixes some of the bugs I will detail below. Maybe it will eventually be deployed by the phone carriers, since they can update the ROM? NOTE per an MS newsgroup posting, SP2 will be in the next SmartPhone SDK release ... whenever that is :)

SoapHeaders

One of the SP2 fixes is supposed to handle how null SoapHeaders are handled. I think the behavior is that if you have a null SoapHeader as InOut on the .NETcf, then it will send the element as xsi:nil= "true", while the full framework will not send the SoapHeader at all. Another has to do with namespace handling. Something to the effect of on the .NETcf I had to explicitly declare a Namespace on a child element to be the same as the parent, while this re-declaration did not have to be done on the full framework. There was a similar issue with XmlAttributes and how they had to be declared more explicitly. Related to this, there is an SP2 fix for XmlTextReader and namespace handling which comes in handy as well.

WS-Utility / Timestamp

I had implemented this previously. All I did was extend it to more fully support the specification. I ran it against the WSE2 Timestamp sample, and it will probably work for the WSE1 Timestamp sample as well. One thing to note is that the SP emulator displayed the same time as my desktop, but its default time zone was (GMT London, Dublin) so all of my calls would fail until I changed the TimeZone and the Time. It was annoying to do this manually, so I wrote a little pInvoke class to handle updating the TimeZoneInformation bias for me. This gets called every time my test app loads, so you would have to modify it to fit your own time zone. Also, if you leave the Emulator running for a while (e.g. about an hour), the time will get out of synch with the desktop by a number of minutes. So if your TimeStamp expiration time is about 5 minutes, then you will start getting TimeStamp expiration SoapFaults. Just restart the emulator and it will synch again.

//request
<Timestamp xmlns="http://schemas.xmlsoap.org/ws/2002/07/utility">
  <Created>2003-11-07T23:48:21Z</Created> 
  <Expires>2003-11-07T23:53:21Z</Expires> 
</Timestamp>

//response
<wsu:Timestamp>
  <wsu:Created>2003-11-07T23:49:34Z</wsu:Created> 
  <wsu:Expires>2003-11-07T23:50:34Z</wsu:Expires> 
</wsu:Timestamp>

Web Reference Wrappers

Instead of changing autogeneated web reference proxies (to add SoapHeaders and such), I always subclass them. This lets me update the web references frequently as the interface changes and not worry about losing any Attributes I have added to that code. The problem is the way I overloaded the WebReference invoke of the WebMethod using the 'new' keyword does not seem to work on the full framework. It fails with the 'methodName' cannot be reflected exception. I think the proxy code generator should be changed to add the virtual keyword. NOTE when I tested on the full framework, my clients typically did not use WSE. WSE clients inherit from Microsoft.Web.Services.WebServicesClientProtocol so they might exhibit different behavior.

{any} and  {@any}

The X in Xml stands for eXtensible. This flows into the specifications themselves. Alot of times you will see {any} and {@any} which represent any XmlElement and any XmlAttribute can show up as valid nodes. Used to be all over HailStorm. If a web service declares them, then your client will be generated with them as well. Great for the .NETfx, but they have issues on .NETcf. On .NETfx, if it is an 'in' SoapHeader with an XmlAnyElement or XmlAnyAttribute, then the WS would get called if you left them as null. Sometimes you would get this behavior on .NETcf. For the TimestampHeader, I would either get a NullReferenceException or an IndexOutOfRangeException and no stream would be sent out for the WS request. I would get similar results if I actually set the values before trying to make the WS call. For retrieving 'out' SoapHeaders from a web service call, I can get XmlAnyElement and XmlAnyAttributes on the SoapHeader itself. If that SoapHeader element contained a sub element that also contained an XmlAnyElement, that would work; but if it contained an XmlAnyAttribute, then it would fail with an exception something like: 'Text' is an invalid node type. Line 1, position 392. So I would typically decorate the SoapHeaders accordingly with XmlAnyElement or XmlAnyAttributes and then comment them out as things broke. NOTE that XmlAnyElement and XmlAnyAttribute are different than UnknownSoapHeaders. XmlAnyElement and XmlAnyAttribute would be child nodes of a known SoapHeader.

//request
<AnyShIn xmlns="http://tempuri.org/" strAttribute="strAttrib">
  <strElement>strElem</strElement> 
  <anyShSub strAttribute="strAttrib">
    <strElement>strElem</strElement> 
  </anyShSub>
</AnyShIn>

//response
<AnyShOut strAttribute="strAttrib" myAnyAttrib="myAnyAttribValue" xmlns="http://tempuri.org/">
  <strElement>strElem</strElement> 
  <anyShSub strAttribute="strAttrib">
    <strElement>strElem</strElement> 
    <myAnyElem myAnyAttrib="myAnyAttribValue" xmlns="" /> 
  </anyShSub>
  <myAnyElem myAnyAttrib="myAnyAttribValue" xmlns="" /> 
</AnyShOut>

Next Page 

Back to .NET Compact Framework | [Article Index]

 

Back to the top of the page.
Chris De Herrera's Windows CE Website Windows CE News & Information Source
Copyright ©2000-2007 by DEVBUZZ.COM, Inc., NJ. USA.MSDEVELOP