views:

933

answers:

2

What is the preferred way using the CF 3.5 to get get data from a web service? I am getting back a series of tables from the web service.

A: 

I've always just used the WebRequest/WebResponse classes; or the HttpWebRequest/HttpWebResponse classes if desired. They are a little tedious to use and not quite as nice as the full frameworks WebClient class, but they work.

John Kraft
+1  A: 

As John points out, its really no different than a desktop call. You can typically add a references to the service from the IDE and let Studio generate the call wrapper, or you can manually hammer it out. Your case might be slightly different if you're attempting to pass a strongly-typed DataSet as the desktop's serialization may not match what the device wants for deserialization. It really depends on your exact usage scenario.

Regardless of your call mechanism, one thing to note is that CF web service calls are painfully slow to generate the proxy. The proxy is cached, but can still take several seconds on the first call to return. A good practice is to have the web service expose a simple dummy method (or a real on if applicable) that does nothing but maybe return a blittable type. When the app fires up, spawn a worker thread to call that method, which will in turn generate the proxy. Then, when you need to call the service for real data, the time is spent only servicing the call, not generating the proxy.

ctacke