Setup a Azure Service Fabric Listener for Service Bus Relay Binding

依然范特西╮ 提交于 2019-12-12 04:36:56

问题


I want to setup a Azure Service Bus Relay between my Service Fabric cluster hosted in Azure and my Private Network.

I can't get the configuration of the Service Bus Relay to work from a Service Fabric WCF service.

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
    return new[]
    {
        // Standard WCF Listener
        new ServiceInstanceListener(context =>
            new WcfCommunicationListener<IFooService>(
                wcfServiceObject: this,
                serviceContext: context,
                endpointResourceName: "WcfServiceEndpoint",
                listenerBinding: WcfUtility.CreateTcpListenerBinding()
            )
        ),
        // Service Bus Relay Listener
        new ServiceInstanceListener(context =>
        {
            var wcfRelay = new WcfCommunicationListener<IFooService>(
                wcfServiceObject: this,
                serviceContext: context);
            wcfRelay.ServiceHost.AddServiceEndpoint(
                    typeof(IFooService),
                    new NetTcpRelayBinding(),
                    ServiceBusEnvironment.CreateServiceUri(
                        "sb",
                        "{mynamespace}.servicebus.windows.net",
                        "{myservce}"))
                .Behaviors.Add(new TransportClientEndpointBehavior
                {
                    TokenProvider =
                        TokenProvider.CreateSharedAccessSignatureTokenProvider(
                            "RootManageSharedAccessKey",
                            "{mykey}")
                });

            return wcfRelay;
        })
    };
}

回答1:


protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
    return new[]
    {
        new ServiceInstanceListener(context =>
        {
            var listener = new WcfCommunicationListener<IFooService>(
                serviceContext: context,
                wcfServiceObject: new FooService(),
                listenerBinding:  new WebHttpRelayBinding(EndToEndWebHttpSecurityMode.None,RelayClientAuthenticationType.None),
                address: new EndpointAddress( ServiceBusEnvironment.CreateServiceUri("https","[ServiceBusNamespace]","[RelayEndPoint]"))
                );

            var ep = listener.ServiceHost.Description.Endpoints.Last();

            ep.EndpointBehaviors.Add(
                new TransportClientEndpointBehavior()
                {
                    TokenProvider = TokenProvider.CreateSharedSecretTokenProvider("owner","[issuerSecret]")
                });
            ep.EndpointBehaviors.Add(
                new ServiceRegistrySettings(discoveryType:DiscoveryType.Public));
            ep.EndpointBehaviors.Add(new WebHttpBehavior());

           return listener;
        })
    };
}


来源:https://stackoverflow.com/questions/43055785/setup-a-azure-service-fabric-listener-for-service-bus-relay-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!