wcf - 是什么导致 Azure 服务总线中继 WCF 服务抛出 AddressAlreadyInUseException

标签 wcf azure-servicebusrelay

当我们尝试使用 Azure 服务总线中继地址和 webHttpRelayBinding 启动 WCF 服务时,我们收到 AddressAlreadyInUseException。

我们在这里使用示例:https://code.msdn.microsoft.com/Relayed-Messaging-Bindings-a6477ba0

除非您使用以下代码创建中继,否则该示例无法正常工作:

string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

var tRelayExists = namespaceManager.RelayExistsAsync("Image");
if (!tRelayExists.Result)
{
    var t = namespaceManager.CreateRelayAsync(new RelayDescription("Image", RelayType.Http));
    Task.WaitAll(t);
    RelayDescription result = t.Result;
}

在 Program.Main() 中执行任何其他工作之前,您需要添加 Azure 服务总线 nuget 包。然后,您需要使用您的 Azure 凭据更新 appSettings 下 App.config 中名为 Microsoft.ServiceBus.ConnectionString 的 ConnectionString。

我们使用 TCPViewer 查看正在使用的端口,没有看到任何冲突。在我们的实际项目中,我们尝试了 webHttpRelayBinding 和 netTcpRelayBinding。归根结底,我们希望使用 netTcpRelayBinding,这样我们就可以使用 DuplexChannels。

对于造成我们问题的原因有什么想法吗?我们是否缺少一些未记录的配置步骤?每个教程都使它看起来很简单,但我们发现每个教程都缺少一些关键步骤。因此,如果我们错过了更多步骤,我不会感到惊讶。

最佳答案

对于使用 NamespaceManager 创建的服务总线实体,我发现绑定(bind) IsDynamic 属性需要设置为 false。这将停止 AddressAlreadyInUseException。

    var binding = new NetTcpRelayBinding();
    binding.IsDynamic = false;

这是我找到答案的地方: http://www.codit.eu/blog/2014/12/securing-azure-service-bus-relay-endpoints-with-sharedaccesssignatures/

关于wcf - 是什么导致 Azure 服务总线中继 WCF 服务抛出 AddressAlreadyInUseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26433728/

相关文章:

.net - IIS7/WPAS : Multiple WCF services in same AppDomain?

c# - 依赖注入(inject) wcf

.net - WAS 和 AppFabric 有区别吗

c# - 适用于 Windows 10 的 AppFabric 支持

c# - Azure服务总线中继连接到未知的IP地址: 40. 112.124.x:9352

azure - 通过 Azure 混合连接访问共享文件夹

c# - 插入和更新的 URI 约定 - WCF Rest API

.net - Azure 服务总线中继中的 304 响应

wcf - 如何以声明方式配置 ServiceBusEnvironment 连接模式

c# - 如何使用 C# 设置 azure 中继混合连接以连接到本地 SQL Server?