.Net Service Bus currently doesn’t support exposing metadata via HTTP Get. Currently it only supports WS-MetadataExchange based metadata generation. I explored various options and came with following solution which seems to be working fine.

  • Expose a REST endpoint with HTTP Get enabled
  • From the implementation of this endpoint, forward the request to real HTTP Get endpoint
  • Send the response data back to the client via Service Bus
  • I have also used the new .Net 4.0 UseRequestHeadersForMetadataAddressBehavior to fix the port and host name in the generated WSDL file

I have packaged all of the above in a custom service behaviour and you can now enable this feature by simply adding this behaviour (line 16) to your service host.

 

  1.     var cred = new TransportClientEndpointBehavior();
  2.     cred.CredentialType = TransportClientCredentialType.SharedSecret;
  3.  
  4.     cred.Credentials.SharedSecret.IssuerName = "owner";
  5.     cred.Credentials.SharedSecret.IssuerSecret = "SHARED-SECERET";
  6.  
  7.     var baseAddress = ServiceBusEnvironment.CreateServiceUri("http", "ServiceNAMESpace", "");
  8.  
  9.     var sh = new ServiceHost(typeof(EchoService), baseAddress);
  10.     var binding = new WS2007HttpRelayBinding(EndToEndSecurityMode.None,RelayClientAuthenticationType.None);
  11.     var endpoint = sh.AddServiceEndpoint(typeof(IEchoService), binding, "Echo");
  12.     endpoint.Behaviors.Add(cred);
  13.  
  14.     //Add SBMetadataBehavior to enable http get metadata via ServiceBus
  15.     sh.Description.Behaviors.Add(new SBMetadataBehavior("metadata"));
  16.  
  17.     sh.Open();

I have upload the complete solution so feel free to download and experiment.