BizTalk Services and "Add Service Reference"

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

     <!-- Application Behaviors -->
     <behavior name="serviceMetadata">
       <serviceMetadata />

Next you define an endpoint - (Notice the binding is the RelayBinding and not the normal metadata binding.)

<endpoint name="MexEndpoint"
          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:// 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"));

Comments (1)

  1. Mehul Gadhia says:

    Hi Justin,

    I always get the "Windows Cardspace" authentication dialog poped up whenever I try to add a Service Reference to my "sb://<SolutionName>/<ServiceName>/<InstanceID>"

    I want to use the UserName / Password authentication instead of Windows Cardspace as my Service is written in Java using the jdotnetservices.

    Please let me know your thoughts on it.

    FYI .. I am using the .Net Services Dec 08 CTP SDK.



Skip to main content