Handling Metadata with Indigo
(Page 1 of 4 )
In this eighth part of a ten-part series on the Windows Communication Foundation (WCF), aka Indigo, you'll learn how to browse and export metadata. This article is excerpted from chapter one of the book
Learning WCF A Hands-on Guide, written by Michele Leroux Bustamante (O'Reilly, 2007; ISBN: 0596101627). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.
Browsing service metadata
In this part of the lab, you'll make changes to the configuration file so that metadata can be viewed in a browser.

Figure 1-25. Creating a new web site with the WCF Service template

Figure 1-26. Solution Explorer view of a new web site based on the WCF Service template
- Before making any changes, test the web endpoint in a browser. Go to Solution Explorer and right-click on the web site project node; select "Set as Startup Project." Run the web site from within Visual Studio (F5). This launches the service endpoint located at http://localhost/IISHostedService/Service.svc in a browser. What you should see is a web page indicating that metadata publishing has been disabled for the service.
Add metadata support to the service model configuration for the web site. Open the web.config file and modify the previously generated service behavior to add the<serviceMetadata>behavior. You will also add a metadata exchange endpoint for the service. The changes are shown in bold in Example1-14.
Example 1-14. Adding metadata browsing support to the web host
<system.serviceModel>
<services>
<service name="HelloIndigo.HelloIndigoService" behaviorConfiguration="returnFaults">
<endpoint contract="HelloIndigo.IHelloIndigoService" binding="basicHttpBinding"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
- Run the web site again (F5). This time you should see the service help page in the browser, providing some instructions for SvcUtil. Leave the browser running and return to Visual Studio.
Without restarting the host, you're going to make a change that enables HTTP GET access to the service metadata. Open the web.config file and sethttpGetEnabledtotrue for the<serviceMetadata>behavior:
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
Save this change and return to the browser instance showing the service help page.
- Refresh the browser (F5) to see what has changed. This time, you should observe the SvcUtil instruction has an active link with a
?wsdl suffix after the service endpoint (see Figure 1-27). Click the link, and you'll be taken to the WSDL document for the service (see Figure 1-28).
Next: Exporting metadata for proxy generation >>
More BrainDump Articles
More By O'Reilly Media
|
This article is excerpted from chapter one of the book Learning WCF A Hands-on Guide, written by Michele Leroux Bustamante (O'Reilly, 2007; ISBN: 0596101627). Check it out today at your favorite bookstore. Buy this book now.
|
|