This sample demonstrates how to expose a metadata endpoint that uses the relay binding. MetadataExchange is supported in the following relay bindings: NetTcpRelayBinding, NetOnewayRelayBinding, BasicHttpRelayBinding and WS2007HttpRelayBinding.
Prerequisites
If you haven't already done so, please read the release notes document that explains how to sign up for a Windows Azure account and how to configure your environment.
Service
The service project is based on the service project in the Echo sample.
To add metadata publishing to the service, modify the application configuration file to include an additional behavior section, as follows:
Xml | |
---|---|
<behavior name="serviceMetadata"> <serviceMetadata /> </behavior> |
This behavior section is then referenced from the services configuration section:
Xml | |
---|---|
<service name="Microsoft.ServiceBus.Samples.EchoService" behaviorConfiguration="serviceMetadata"> <endpoint name="RelayEndpoint" contract="Microsoft.ServiceBus.Samples.IEchoContract" binding="netTcpRelayBinding" address="" /> <endpoint name="MexEndpoint" contract="IMetadataExchange" binding="ws2007HttpRelayBinding" bindingConfiguration="mexBinding" address="" /> </service> |
For the service to authenticate with the Service Bus, you are
prompted to enter the service namespace and the issuer credentials. The issuer
name is used to construct the service URI.
Next, the sample creates a service endpoint and a MEX endpoint. It then adds the
TransportClientEndpointBehavior
and opens a service endpoint.
C# | |
---|---|
Uri sbAddress = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "Echo/Service"); Uri httpAddress = ServiceBusEnvironment.CreateServiceUri("http", serviceNamespace, "Echo/mex"); ... TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); ... ServiceHost host = new ServiceHost(typeof(EchoService), address); ... host.Open(); |
Client
In this sample, the client is the Svcutil.exe tool.
Note: Svcutil.exe is installed as part of the Windows SDK. A typical location might be C:\Program Files\Microsoft SDKs\Windows\<version>\Bin\NETFX 4.0 Tools\SvcUtil.exe |
Building and Running the Sample
To run the sample, build the solution in Visual Studio or from the command line. After building the solution, do the following to run the application.
- From a command prompt, run the service (Service\bin\Debug\Service.exe) as administrator.
- Copy the svcutil.exe.config included with this solution in the same directory as svcutil.exe. If svcutil.exe.config already exists, add the bindingExtensions, policyImporters, and wsdlImporters of the attached svcutil.exe.config to it.
- From another command prompt with elevated privileges, run the .NET 4.0 svcutil
against the mex endpoint opened by the service:
svcutil.exe
http://<service-namespace>.servicebus.windows.net/Echo/mex/,
replacing <service-namespace> with the your service namespace.
Note: In a 32-bit machine, a typical machine.config will be at
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config. In a 64-bit machine, machine.config will be both at a typical machine.config will be at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config and a typical machine.config will be at C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config. Depending on whether the application is running as 32-bit or 64-bit, the appropriate one should be updated. |
Expected Output – SvcUtill
SvcUtil.SvcUtil.exe /d:c:\ http://<service-namespace>.servicebus.windows.net/Echo/mex Microsoft (R) Service Model Metadata Tool [Microsoft .NET Framework, Version 3.0.50727.357] Copyright (c) Microsoft Corporation. All rights reserved. Generating files... C:\EchoService.cs C:\output.config |
Expected Output – output.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <netTcpRelayBinding> <binding name="RelayEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Buffered" connectionMode="Relayed" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Transport" relayClientAuthenticationType="RelayAccessToken"> <transport protectionLevel="EncryptAndSign" /> <message clientCredentialType="Windows" /> </security> </binding> </netTcpRelayBinding> </bindings> <client> <endpoint address="sb://<issuer-name>.servicebus.windows.net/services/Echo/" binding="netTcpRelayBinding" bindingConfiguration="RelayEndpoint" contract="IEchoContract" name="RelayEndpoint" /> </client> </system.serviceModel> </configuration> |
Did you find this information useful? Please send your suggestions and comments about the documentation.