[英]Sending to Service Bus Event Hubs from a WCF Message Inspector
我有一個正常工作的Web服務和測試客戶端,可以攔截它們之間的消息。 但是,當我添加要發送到事件中心的代碼時,客戶端顯示錯誤:
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添加端點,以便能夠將數據發送到Service Bus Event Hub。 如果是這樣,如何配置?
提前致謝
背景 :
ServiceBus SDK具有2個主要接口:
aka Control Plane
),例如創建刪除主題/ EHub等 aka Data Plane
)-從Topics / EventHubs發送/接收。 這兩個接口都需要它們自己的連接字符串才能連接到ServiceBus。 例如:為NamespaceManager指定的連接字符串將需要ManageClaims,而對於EntityClients,僅需要發送/接收聲明。
您僅使用EventHub Name創建了EventHubClient,並且未在其中傳遞連接字符串。 在這種情況下,如果未通過app.config傳遞連接字符串,則會從我們的ServiceBus客戶端sdk拋出上述錯誤。 要解決此問題,請更改此行(因為您將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.
HTH! SREE
實際上,我所需要做的就是用連接字符串編輯Web服務服務器的應用程序配置。 似乎eventhubclient的Create方法使用eventhub名稱,然后轉到appconfig作為密鑰,因此找不到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.