One of the little known features of BizTalk Services is it’s support for metadata. There’s a sample in the SDK (default path: C:\Program Files\Microsoft BizTalk Services SDK\Samples\Communication\ExploringFeatures\Metadata\MetadataExchange\CS30) that shows you how to listen for incoming metadata requests through the relay. It tracks with the WCF metadata story and is built on WCF extensibility points. In fact, if you open the machine.config file, you will see the policy importers and the WSDL extensions.
The end user experience is quite simple. At some point, you setup the service behavior
<behaviors> <serviceBehaviors> <!-- Application Behaviors --> <behavior name="serviceMetadata"> <serviceMetadata /> </behavior> </serviceBehaviors> </behaviors>
Next you define an endpoint – (Notice the binding is the RelayBinding and not the normal metadata binding.)
<endpoint name="MexEndpoint" contract="IMetadataExchange" binding="relayBinding" bindingConfiguration="default" address="mex" />
That’s about all that’s required to expose metadata.
Consuming it is just as easy. From a new VS project, all you have to do is right click the project and select "Add Service Reference" (VS 2008).
In the next window, enter the service bus URI (like sb://connect.biztalk.net/services/justinjsmith/Echo) and click Go:
When you click OK, the tooling (think svcutil) will generate the proxy code and config for you. In an empty project, literally the only two lines of code you have to write are:
EchoContractClient client = new EchoContractClient(); Console.WriteLine(client.Echo("hi there"));