BizTalk Server and WCF Support in Visual Studio 2008
|To download a copy of this document, go to http://go.microsoft.com/fwlink/?LinkId=142354.|
Microsoft® Visual Studio® 2008 provides robust support for solutions that use the Windows® Communication Foundation (WCF) and Microsoft BizTalk® Server 2009. While some of the functionality is clearly visible, some of it may not be evident to a BizTalk application developer how to take full advantage of these options.
|This document refers to the Beta release of BizTalk Server 2009.|
The purpose of this whitepaper is to provide a clear and concise summary of the capabilities exposed by Visual Studio in support of BizTalk Server and WCF. That paper contains an explanation for the BizTalk application developer how each feature can help you in your complete BizTalk Server and WCF solution. You can view this as a high-level explanation of how Visual Studio 2008 can help support your BizTalk Server and WCF development and integration.
|This paper does not provide a detailed description of how to use each feature. Please refer to the product documentation to get that information.|
In the future, BizTalk Server will rely more and more upon WCF. You can clearly observe this movement through the capabilities of the WCF adapters that ship with BizTalk Server 2009. These adapters work to support BizTalk Server applications in their communication and extensibility with WCF. Also, the WCF LOB (Line-of-Business) version 2.0 adapters can run outside of BizTalk Server as independent WCF entities. WCF adapters offer support for extending custom BizTalk Server WCF operations in the form of custom behaviors and custom bindings. In BizTalk Server 2009, you can see that WCF is used through many different mechanisms.
Configuring WCF and BizTalk Server 2009
BizTalk Server applications that use WCF require installation of the Windows Communication Foundation Adapter as well as the Windows Communication Foundation Administration Tools. You can choose to install these options during setup of BizTalk Server 2009.
On any computer that requires WCF capability, review the One-Time Set Up Procedure for the Windows Communication Foundation Samples at http://go.microsoft.com/fwlink/?LinkId=135510. While this paper is primarily focused on configuring the system to host the WCF samples, it also provides a wealth of information on how to set up your computers to ensure WCF, BizTalk Server, Internet Information Services (IIS), and Windows Server® 2008 all work correctly together.
Configuring Visual Studio 2008
There are no special options to install WCF support with Visual Studio 2008. Installing the language of your choice and the default Visual Studio environment ensures that you will be able to use all the WCF functionality described in this paper. You should also install the .NET Framework 3.5 prior to installing Visual Studio 2008. During setup you will be prompted to choose this option. If you need to install the .NET Framework manually, you can do so from http://go.microsoft.com/fwlink/?LinkId=142173.
For BizTalk Server 2009, after installing Visual Studio 2008, you will need to install the Developer Tools and SDK option. This will allow you to execute BizTalk Server related development and configuration tasks from within Visual Studio 2008. For more information on installing and configuring BizTalk Server 2009, see the BizTalk Server product documentation.
Visual Studio 2008 allows you to easily create and interact with WCF services and clients. It also allows you to easily integrate with BizTalk Server 2009, its enterprise functionality, and the WCF Adapters. You therefore need to understand the WCF capabilities of Visual Studio both independent of, and integrated into, BizTalk Server 2009.
We will start at the basic level and work into the more complex capabilities. The basic WCF paradigm is a WCF client calling a WCF service. To use the capabilities of Visual Studio to create a WCF client, you first need a WCF service. Fortunately, you do not have to begin writing a WCF service from scratch. Visual Studio 2008 allows you to quickly create a WCF service library using the .NET Framework 3.5. You can do this under New Project > Visual C# > WCF/WCF Service Library. This creates the following files (where “ServiceName” is the name of your project when you are creating the new WCF service library):
configuration file (.cfg)
service contract (IServiceName.cs)
service implementation (ServiceName.cs)
After your service is complete, Visual Studio 2008 allows you to test the WCF service. Visual Studio provides a Windows Forms WCF Client test application that appears simply by running the WCF Service from within Visual Studio 2008. Using this WCF client, you can send requests to each exposed operation and displays the response.
For more information on creating and testing your WCF service, see Walkthrough: Creating and Accessing WCF Services.
Manually writing, navigating, and modifying a configuration file can be confusing. During the process of creating a new WCF service library, Visual Studio 2008 inserts an App.config file into the project. Manual modifications of this file is simplified with the help of coloring and Intellisense from within Visual Studio. However, this is prone to subtle errors and requires a deep understanding of configuration files.
The recommended editing option is to right-click on the App.config file in Solution Explorer and select Edit WCF Configuration to invoke the Microsoft Service Configuration Editor. (Alternatively, this editor can be invoked from the Tools menu). This tool is very useful in allowing you to quickly create and configure elements such as custom bindings, trace listeners, WCF endpoints and endpoint behaviors, binding and behavior element extensions, diagnostic settings, and other WCF configuration settings.
For more information on using the Microsoft Service Configuration Editor, refer to Configuration Editor Tool (SvcConfigEditor.exe).
Refer to the following documents in the Visual Studio 2008 product documentation to understand the process of deploying a WCF service.
If you are developing a client for a WCF service, you can easily add a reference to this service in your client application. Adding the service reference creates subfolders and files (WSDL, XSD, DISCO, and a proxy file) for you to access the WCF service from your client code.
|Ensure the WCF service for which you want to add a reference is running or hosted in IIS when try to add a reference.|
Confirm the WCF service is running or hosted in IIS.
Right-click on your WCF client project, and then select Add Service Reference.
Enter the endpoint URI.
In your client code, add a reference to the namespace of the service and use that proxy variable to access the WCF service.
For more information, see Add Service Reference Dialog Box.
After adding a reference to a WCF service, you can modify it if needed. For instance, you may want to change the value of the exposed endpoint URI or the data type. To do this, right-click the service reference in Solution Explorer, and then select Configure Service Reference.
|Adding a service reference from within Visual Studio 2008 is somewhat similar to running the ServiceModel Metadata Utility tool (svcutil.exe) against the metadata of a service (for instance, a WDSL file). This tool generates code containing the client class and a corresponding configuration file. To use the service, you add these files to your client application. From within your client code you will use the generated client class to communicate with the service. For more information on the ServiceModel Metadata Utility tool, refer to Generating a WCF Client from Service Metadata.|
Sometimes you may add a reference to a WCF service that is hosted in IIS to your client code. But how does one host a service in IIS in the first place?
Visual Studio 2008 lets you create a new Web site for a WCF service from File > New > Web Site > WCF Service. This process creates a project with all the files you need to create a WCF Web site whose metadata is discoverable by various tools (where “ServiceName” is the name of your project when you are creating the new WCF service library):
ServiceName.svc file (browsed by svcutil.exe)
Service contract (IServiceName.cs)
Service implementation (ServiceName.cs)
After you complete development of your Web site, you can choose Build Web Site from the Build menu. This process of pre-compilation identifies any configuration file and compilation errors at build time instead of more carelessly at run time. Because the pages are pre-compiled, retrieval speed on the very first access is increased for the pages. You will typically publish to a folder in the C:\inetpub\wwwroot folder structure that corresponds to a standard virtual directory folder that hosts the service in IIS. This allows browsing of the services metadata, followed by automatic activation when accessed by a client application, if needed.
|You need to promote a virtual directory to an application in IIS to allow browsing of its .svc file.|
For more information on creating, building, and publishing a Web site in Visual Studio 2008, refer to Walkthrough: Publishing a Web Site.
You may already be familiar with the BizTalk WCF Service Publishing Wizard that ships with BizTalk Server 2009. This tool takes a BizTalk orchestration and publishes it as a Web service so it can be called by various WCF client applications.
The corresponding tool to the Publishing Wizard is the BizTalk WCF Service Consuming Wizard, which exists only within the Visual Studio 2008 environment. A BizTalk orchestration that calls a WCF service uses the Consuming Wizard to streamline the process. Right-click on the BizTalk Server project, and select Add > Add Generated Items > Generated Schema Files > Consume WCF Service. This invokes the BizTalk WCF Service Consuming Wizard to consume metadata from a MEX endpoint or a set of WSDL/XSD files depending upon how the service exposes its metadata. The imported metadata results in the following files added to the BizTalk project:
A binding file to be imported into a BizTalk application to create the send port for the orchestration to consume the WCF service.
Note You will want to first deploy the BizTalk orchestration into BizTalk Server 2009 before importing this binding file.
An empty orchestration to consume the WCF service.
XSD files used by the orchestration during access of the WCF service.
For additional information, refer to BizTalk WZF Service Consuming Wizard.