MSDN Magazine - December 2007 - (Page 59) The Sample Solution The solution I’ll be building is deliberately simple so that I can focus on the individual technologies and integration issues rather than the business functionality. Figure 1 gives you an idea of the user experience. There are two processes involved: a standalone WCF service hosted in a console application and a VSTO add-in running in Word 2007. The add-in offers a custom task pane, which includes a WPF custom control. As the user clicks the buttons in the control, the add-in responds by calling into the WCF service to fetch some XML data. The add-in then processes this data in a variety of ways, using LINQ and XLinq, including lambda expressions and expression trees, and formats text that it then inserts into the active document. If you want to work through the sample solution yourself, download and install the Visual Studio 2008 Beta 2 release, available at msdn2.mi crosoft.com/vstudio/aa700831. The point of this sample is not to show the specific runtime functionality; instead, the main idea is to demonstrate that all the new Visual Studio 2008 technologies (WPF, WCF, and LINQ) work seamlessly with Office solutions. Another goal of this sample solution is to provide food for thought for building exciting new Figure 1 Runtime Behavior of the Sample Solution user experiences. Figure 2 illustrates the architecture of the solution. Using WCF ImageServiceHost. My next step was to add a WCF Service item and LINQ within a VSTO application offers a lightweight approach to the project, which I decided to call ImageService. It is important and is no different than using these features in a Windows Forms for you to understand that adding a Windows Communication or console application. Using WPF is more interesting, though, Foundation Service to the project in Visual Studio causes startas you’ll see. er code to automatically be generated for the service, including One aspect of VSTO is the ability to build solutions that use an interface that represents the service contract and class that managed controls within native Office UI windows. VSTO sup- implements that interface. Configuration entries that specify beports placing managed (Windows Forms) controls in arbitrary haviors and endpoints for the service are provided in a standard Windows Forms dialogs, in app-level custom task panes, in the app.config file. document actions pane, in Outlook® custom form regions, and I had to change the service contract and its implementation in on the surface of a Word or Excel document. The Microsoft .NET order to remove the wizard-generated DoWork method and reFramework 3.5 (shipping with Visual Studio 2008) includes the WindowsFormsIntegration.dll, which contains 2 Console Host Winword.exe the Windows Forms Integration ElementHost class. This 4 Service Insert provides a bridge between Windows Forms and WPF. WCF Service Call VSTO Add-in Text Thus, VSTO also supports placing WPF controls in all 3 LINQ WCF Service the places you can put Windows Forms controls. Processing Client Proxy Data One of the interesting design decisions you get to Query make here is where to handle events. For example, when Custom Task Pane 1 the user clicks one of the WPF Button controls, you can Click handle this at multiple levels: in the WPF UserControl, Windows Forms Custom UserControl Event in the Windows Forms UserControl, or in the add-in. Windows Forms Integration ElementHost Where you handle the event, and whether you bubble WPF Custom UserControl it up further, depends a lot on how reusable you want the various controls to be. WPF Custom Panel Building the WCF Service The way I went about starting to build the project is I began with a simple console application called Figure 2 Architecture of the Sample Solution december2007 59 http://msdn2.microsoft.com/vstudio/aa700831 http://msdn2.microsoft.com/vstudio/aa700831
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.