Tuesday, December 05, 2006

Exposing a MEX Endpoint

Today I found out the following. Let's say you have an Indigo service using the basic profile binding (BasicProfile) or any of the WS-* profiles. Then, you need a way to expose the metadata of your service to clients. Normally, you will define a new WS-MetatadataExchange (MEX) endpoint. But here is the trick. If your service is self-hosted, then if you specify a base address while opening the service, then you have this MEX endpoint created for you. Just point to the base address in your Web browser, and you will get the service description file or if you want the WSDL - just type the "?wsd" in the address bar. Here is a sample code that demonstrates this:

Uri baseAddress = new Uri( "http://localhost:8080/MEXAutoMetadataSvc" );

// NOTE: by specifying a base address, the MEX endpoint should be automatically populated especially for HTTP based profiles
myServiceHost = new ServiceHost( typeof( .. MEXAutoMetadataSvc ),
new Uri [] { baseAddress } );

//Open myServiceHost
myServiceHost.Open();

Now with this code running, if you go to http://localhost:8080/MEXAutoMetadataSvc you will see the description for this service.

No comments:

Post a Comment