Welcome to Windows Communication Foundation (WCF)
Top Tasks :

WCF Community Bloggers

WCF: About Exposing Metadata

Everything about WCF is about keeping your service boundary intact . By default this also applies to exposing/publishing metadata . In ASMX days, one would need to opt-out of exposing metadata, while in WCF, one has to opt-in . Let's say, for example, you have the following service config declaration: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name = "Exposing.Metadata"> <host> <baseAddresses> <add baseAddress = "http://localhost:123/MetadataService "> </baseAddresses> </host> <endpoint address = "" binding = "wsHttpBinding" contract = "Exposing.IServiceContract"/> </service> </services> </system.serviceModel> </configuration> This would host Exposing.Metadata service and define a single wsHttpBinding based endpoint listening at the base address. So, the service endpoint address is http://localhost:123/MetadataService . If you would hit the endpoint URL with a web browser, a nice service page would be returned telling you that you have created a service, but there is no metadata exposed . So, hitting the endpoint with svcutil.exe would not allow you to grab metadata and generate the proxy code. WCF, by default, does not expose any metadata . You have to ask for it nicely . There are a couple of options to expose metadata of WCF services. The most basic way of doing it would be to expose it via HTTP based Get requests and retrieve WSDL. The following code fragment would do it, if you hosted the service using a ServiceHost class: [ 1] using (ServiceHost sh = new ServiceHost(typeof(OpService))) [ 2] { [ 3] ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); [ 4] smb.HttpGetEnabled = true; [ 5] sh.Description.Behaviors.Add(smb); [ 6] sh.Open(); [ 7] Console.WriteLine("Service running..."); [ 8] [ 9] Console.ReadLine(); [10] sh.Close(); [11] } Lines 3-5 instantiate and add a service behavior that allows a simple HTTP Get Read More...
Published Monday, February 19, 2007 8:05 AM by Matevz Gacnik's Weblog
Filed under:

Comments

No Comments
Anonymous comments are disabled

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us