MSDN Magazine Launch Issue - February 15, 2008 - (Page 42) The .NET Compact Framework 3.5 does not ship with support for the WCF Service Model, which would support hosting and calling services without all the plumbing code for sending } and receiving messages. But with the proper helper classes, callAnd you’re done! Let’s run it! ing WebMethods on ASP.NET Web services, WCF services, and other WSDL-compliant services using Compact WCF can be just Running the Sample Build and deploy your device project. Be sure to deploy your de- as easy as calling a method. The .NET Compact Framework 3.5 PowerToys ship with a tool, vice application to the same emulator or device that your mail account is configured on. Start each project individually. In Solution NetCFSvcUtil.exe, that generates these service proxy classes for you. Explorer, right-click on the device project’s item and select Debug Since NetCFSvcUtil.exe does not ship with Visual Studio 2008, you | Start new instance. Repeat for the desktop project. Figure 8 shows need to download the Power Toys for .NET Compact Framework 3.5 at msdn2.microsoft.com/aa497280. what the device app should look like. Because the .NET Compact Framework 3.5 ships with a subset Go ahead and enter your Exchange e-mail address into the To: field of each application. Type a message and click Send. While of the bindings that you’ll find with WCF on the desktop, a service you’re waiting for the message to appear on the other app, let me must expose an endpoint that uses bindings supported by the .NET Compact Framework. You can also write your own bindings using explain what is happening and how you can watch it. When either app sends a message, the text string you send is Compact WCF, but that is beyond the scope of this article. Now let’s construct a .NET Compact Framework-compatible wrapped inside a SOAP envelope and dropped in your outbox. WCF service on the desktop and write an appliExchange picks it up and sends it to the recipient’s cation that calls into that service using a proxy inbox (your own in this case). Each app is polling class generated by NetCFSvcUtil.exe. For the seryour inbox looking for messages with a matching vice application, create a new WCF Service Web channel name. Once it notices the waiting message, site in Visual Studio 2008, verifying that .NET the application will download the message, delete it Framework 3.5 is selected in the upper-right-hand from the server (or move it to your Deleted Items corner of the New Web Site dialog. For brevity’s folder), and process it by deserializing the string sake, go ahead and accept the WCF service exactly out of the envelope’s body tag and appending that as the Visual Studio 2008 template gives it to you. string to the conversation history textbox. That gives you automatically created GetData and If you’re interested in how the SOAP-crafted eGetDataUsingDataContract methods. mail looks, you can check your outbox or inbox Since the .NET Compact Framework 3.5 does (if you check before the app finds and deletes it) or not support wsHttpBinding, you need to either look through your Deleted Items folder (if the app change the default endpoint Visual Studio created has already processed the message). to basicHttpBinding or add a new endpoint of that A number of things can go wrong as you write or configure this application. If messages do not Figure 8 Sending a Message type. Since WCF makes it so easy to expose multiple endpoints, and since wsHttpBinding adds security show up where you expect them, check your Inbox and Outbox folders in Outlook or Pocket Outlook for messages for those apps that will support it, let’s leave it there and add a new to see if they are being sent and/or received. If messages are just endpoint that uses basicHttpBinding. Open your WCF service’s web.config file. Find the sitting in the Pocket Outlook Outbox or the Outlook Inbox but not syncing, check that your device is connected to your Exchange tags and add a new one with an address of basic and with the bamail account and force ActiveSync on your device to send and re- sicHttppBinding binding: ceive messages. If messages seem to be delivered to the appropri ate Inboxes but your application just doesn’t pick them up, verify Since the method that receives messages runs on a background thread, any exception that terminates the thread will not be visible Check your service by right-clicking your Web project’s Service.svc to your UI. It’s possible that something went wrong and your app project item in Solution Explorer and clicking View in Browser. Note that with BasicHttpBinding comes a few limitations on is no longer listening for messages. Check your debugger’s Output window for an exception stack trace to see if anything has gone what you can do with your service. For instance, duplex service wrong. You might use your debugger to see if you have a thread contracts, transactions, and callbacks are not supported. If you still waiting for messages. In a business app you would want to try to use a BasicHttpBinding endpoint to expose a service that add exception handeling and perhaps diagnostic logging to this uses any of these features (or a few others), you will get a runtime error from WCF. background thread. 42 msdnmagazine Mobile WCF } else { historyBox.Dispatcher.Invoke(DispatcherPriority.Normal, (Messaging .IncomingMessageCallback)incomingMessage, message); } Calling WCF Services http://msdn2.microsoft.com/aa497280
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.