从WCF消息检查器发送到服务总线事件中心

时间:2015-04-10 10:27:23

标签: web-services wcf endpoints idispatchmessageinspector azure-eventhub

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

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 Console应用程序最多打印

Creating Event Hub
Created

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

先谢谢

2 个答案:

答案 0 :(得分:3)

<强>背景

ServiceBus SDK有两个主要接口:

  1. NamespaceManager:用于所有管理操作(aka Control Plane),如创建删除主题/ EHubs等
  2. EntityClients(TopicClient,EventHubClient等):用于运行时操作(aka Data Plane) - 从Topics / EventHubs发送/接收。
  3. 这两个接口都需要自己的连接字符串才能连接到ServiceBus。例如:指定给NamespaceManager的连接字符串需要ManageClaims,而EntityClients只需要发送/接收索赔。

    您使用EventHub Name创建了EventHubClient,并且没有在那里传递连接字符串。在这种情况下,从ServiceBus客户端sdk抛出上述错误 - 当连接字符串未通过app.config传递时。 要解决此问题,请更改此行(因为您直接为NamespaceManager使用ConnectionString而不使用任何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.
    

    HTH! SREE

答案 1 :(得分:-1)

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