Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Last active November 23, 2017 11:18
Show Gist options
  • Save CoditCompany/68053802758145e2124b to your computer and use it in GitHub Desktop.
Save CoditCompany/68053802758145e2124b to your computer and use it in GitHub Desktop.
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="sbbehavior">
<transportClientEndpointBehavior>
<tokenProvider>
<sharedAccessSignature keyName="SendAccessKey" key="xxx=" />
</tokenProvider>
</transportClientEndpointBehavior>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpRelayBinding>
<binding name="sbBinding" isDynamic="false" />
</basicHttpRelayBinding>
</bindings>
<client>
<endpoint address="https://xxx.servicebus.windows.net/us/myservice" binding="basicHttpRelayBinding" bindingConfiguration="sbBinding" behaviorConfiguration="sbbehavior" contract="wcfService.IService1" name="sbendpoint" />
</client>
</system.serviceModel>
NamespaceManager nsManager = NamespaceManager.CreateFromConnectionString("Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxx=");
var relayDescription = new RelayDescription("us/myservice", RelayType.Http)
{
RequiresClientAuthorization = true,
RequiresTransportSecurity = true
};
var sendKey = SharedAccessAuthorizationRule.GenerateRandomKey();
var sendKeyName = "SendAccessKey";
var listenKey = SharedAccessAuthorizationRule.GenerateRandomKey();
var listenKeyName = "ListenAccessKey";
relayDescription.Authorization.Add(new SharedAccessAuthorizationRule(listenKeyName, listenKey,
new List<AccessRights> { AccessRights.Listen }));
relayDescription.Authorization.Add(new SharedAccessAuthorizationRule(sendKeyName, sendKey,
new List<AccessRights> { AccessRights.Send }));
try
{
var relay = await nsManager.CreateRelayAsync(relayDescription);
}
catch (MessagingException ex)
{
Console.WriteLine(ex);
}
Console.WriteLine("Listen access rule created with key '{0}' and name {2} on entity '{1}'", listenKey, relayDescription.Path, listenKeyName);
Console.WriteLine("Send access rule created with key '{0}' and name {2} on entity '{1}'", sendKey, relayDescription.Path, sendKeyName);
<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint address="https://xxx.servicebus.windows.net/us/myservice" behaviorConfiguration="sbbehavior" binding="basicHttpRelayBinding" bindingConfiguration="sbBinding" name="sbendpoint" contract="WcfService1.IService1" />
</service>
</services>
<bindings>
<basicHttpRelayBinding>
<binding name="sbBinding" isDynamic="false" />
</basicHttpRelayBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="sbbehavior">
<transportClientEndpointBehavior>
<tokenProvider>
<sharedAccessSignature keyName="ListenAccessKey" key="xxx=" />
</tokenProvider>
</transportClientEndpointBehavior>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment