1

我有一个工作的网络服务和测试客户端,我可以拦截它们之间的消息。但是当我添加要发送到我的事件中心的代码时,客户端显示错误:

An unhandled exception of type 'System.ServiceModel.FaultException`1' occurred in mscorlib.dll

Additional information: The argument Endpoints is null or empty.

Parameter name: Endpoints

更详细的例外:

System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]:    The argument Endpoints is null or empty.
Parameter name: Endpoints (Fault Detail is equal to An ExceptionDetail,  likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.ArgumentException: The argument Endpoints is null or empty.
Parameter name: Endpoints
at Microsoft.ServiceBus.ServiceBusConnectionStringBuilder.Validate()
at Microsoft.ServiceBus.ServiceBusConnectionStringBuilder.ToString()
at  Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.
Initialize(String connection, Nullable`1 transportType)
at Microsoft.ServiceBus.Messaging.Configuration.KeyValueConfigurationManager.
.ctor(Nullable`1 transportType)
at Microsoft.ServiceBus.Messaging.EventHubClient.Create(String path)
at WCFInterceptor.MessageInspector.AfterReceiveRequest(Message& request,  ICli
entChannel channel, InstanceContext instanceContext)
at  System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.AfterReceiveReques
tCore(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(Me
ssageRpc& rpc)
at System.ServiceModel.Dispatc...).

这是我添加的代码:

try
        {
            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(GetServiceBusConnectionString());
            Manage.CreateEventHub(hubName, 16, namespaceManager);
        }
        catch (Exception e)
        {
            Console.WriteLine("SetupEHError" + e);
        }
        EventHubClient client = EventHubClient.Create(hubName);
        Console.WriteLine("eventhubclient iniciado");
        EventData messageData = new EventData(Encoding.UTF8.GetBytes(serializedString));

        try
        {
            client.Send(messageData);
            Console.WriteLine("MessageData enviada");
        }
        catch (Exception e)
        {

            Console.WriteLine("ErrorMessage:" + e);
        }

这是 CreateEventHub 方法:

public static void CreateEventHub(string eventHubName, int        numberOfPartitions, NamespaceManager manager)
    {
        try
        {
            // Create the Event Hub
            Console.WriteLine("Creating Event Hub...");
            EventHubDescription ehd = new EventHubDescription(eventHubName);
            ehd.PartitionCount = numberOfPartitions;
            manager.CreateEventHubIfNotExistsAsync(ehd).Wait();
            Console.WriteLine("Created");
        }
        catch (AggregateException agexp)
        {
            Console.WriteLine(agexp.Flatten());
        }
    }

WebService 控制台应用程序最多可打印

Creating Event Hub
Created

所以我在想我可能需要为 WebService 中的 MessageInspector 添加端点,以便能够将数据发送到服务总线事件中心。如果是这样,配置如何?

提前致谢

4

2 回答 2

3

背景

ServiceBus SDK 有 2 个主要接口:

  1. NamespaceManager:用于所有管理操作(aka Control Plane),如创建删除主题/EHubs 等
  2. EntityClients(TopicClient、EventHubClient 等):用于运行时操作 ( aka Data Plane) - 从 Topics/EventHubs 发送/接收。

这两个接口都需要自己的连接字符串来连接到 ServiceBus。例如:指定给 NamespaceManager 的连接字符串需要 ManageClaims,而 EntityClients 只需要 Send/Recv 声明。

您仅使用 EventHub 名称创建了 EventHubClient 并且没有在那里传递连接字符串。在这种情况下,我们的 ServiceBus 客户端 sdk 会抛出上述错误 - 当连接字符串未通过 app.config 传递时。要解决此问题,请更改此行(因为您将 ConnectionString 直接用于 NamespaceManager 而没有使用任何 app.config):

EventHubClient client = EventHubClient.Create(hubName);

将其更改为:

----edit-----
    var eHubConnStr = GetServiceBusConnectionString();
    eHubConnStr.EntityPath = eventHubName;
    // Evaluate here, if you have to populate the Security related properties from the ConnectionString
    // eHubConnStr.SasKey and SasKeyName to Send only or Recv only
----edit-----
    EventHubClient client = EventHubClient.CreateFromConnectionString(eHubConnStr); // this connection string should be the EventHub Send conn str.

!斯里

于 2015-04-13T20:27:30.967 回答
-1

实际上,我需要做的就是使用连接字符串编辑我的 Web 服务服务器的应用程序配置。似乎 eventthubclient 的 Create 方法采用 eventthub 名称,然后转到 appconfig 获取密钥,因此没有找到它。

于 2015-04-16T09:32:10.360 回答