.NET CoreコンソールアプリケーションからAzureサービスバス経由でメッセージを送信し、.NET 4.6コンソールアプリケーションで受信したいとします。 .NET Coreでは、Azureの新しいサービスバスクライアントを送信側に使用していますが、これは生産のためのものではありません(readmeに従って)。.NETコア送信者から.NET 4.6ハンドラにAzure ServiceBusでメッセージを送信
https://github.com/Azure/azure-service-bus-dotnet
私は、.NETのコアから送信したサンプルを使用して簡単に十分な.NETのコアで受け取ることができます。しかし、.NET 4.6アプリがトピックにサブスクライブし、同じメッセージを受信し、.NET 4.6アプリは、この例外をスローする場合:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:
Exception while executing function: Functions.ProcessEvent
System.InvalidOperationException: Exception binding parameter 'message'
The BrokeredMessage with ContentType 'string' failed to
deserialize to a string with the message:
'Expecting element 'string' from namespace
'http://schemas.microsoft.com/2003/10/Serialization/'..
Encountered 'Element' with name 'base64Binary', namespace
http://schemas.microsoft.com/2003/10/Serialization/'. ' --->
System.Runtime.Serialization.SerializationException: Expecting element
'string' from namespace
http://schemas.microsoft.com/2003/10/Serialization/'.. Encountered 'Element'
with name 'base64Binary', namespace
'http://schemas.microsoft.com/2003/10/Serialization/'.
System.Runtime.Serialization.DataContractSerializer.InternalReadObject
(XmlReaderDelegator xmlReader, Boolean verifyObjectName,
DataContractResolver dataContractResolver) at
System.Runtime.Serialization.XmlObjectSerializer.
ReadObjectHandleExceptions(XmlReaderDelegator reader,
Boolean verifyObjectName, DataContractResolver dataContractResolver)
マイ.NETのコアの送信者コードは次のとおりです。
using Microsoft.Azure.ServiceBus;
var topicClient = new TopicClient(ServiceBusConnectionString, "topic1");
var msg = new Message(Encoding.UTF8.GetBytes("Hello world"));
topicClient.SendAsync(msg).Wait();
マイ.NET 4.6受信機のコードがある:それは、レガシーシステムのよう
using Microsoft.Azure.WebJobs;
static void Main()
{
var config = new JobHostConfiguration();
config.UseTimers();
config.UseServiceBus();
var host = new JobHost(config);
host.RunAndBlock();
}
public void ProcessEvent([ServiceBusTrigger("topic1", "the-same-endpoint-as-connection-string")] string message, TextWriter logger)
{
Console.Writeline(message);
}
注私は、受信機を変更することはできません。
コンソールアプリケーションのハンドラコードを追加できますか?どのようにメッセージを読もうとしていますか? –
.NETシリアライザに問題があるようですが、JSONシリアライズを使用できますか? –
キューrawバイトを送信しますが、もう一方の側で文字列を受け取ることを期待します。メッセージのメタ情報の一部はコンテンツタイプですが、あなたが送信したバイトの種類がわからないため、バイト - >文字列変換で何をすべきか分からないと思います。 –