Azure Service Bus トピックにサブスクライブしたときに受信したメッセージを解析しようとすると、シリアル化例外が発生します。私が欠けているものを見た人はいますか?Silverlight コードに Microsoft.ServiceBus.Samples.Messaging を使用しています。
次のコードを含む Web サービスがあります。
public void PushCommand(Command command, int posLocationId)
{
var topicName = "topicName";
var topicClient = TopicClient.CreateFromConnectionString(ConnectionString, topicName);
try
{
var message = new BrokeredMessage("test");
topicClient.Send(message);
}
...
}
次のコードを持つ SilverLightClient があります。
private void OnReceiveMessageCompleted(IAsyncResult result)
{
var subscriptionClient = (SubscriptionClient)result.AsyncState;
try
{
var message = subscriptionClient.EndReceive(result);
if (message != null)
{
String s = message.GetBody<string>();
}
// prep for next message
subscriptionClient.BeginReceive(this.OnReceiveMessageCompleted, subscriptionClient);
}
catch (Exception e)
{
//unknown error
}
}
SerializationException がキャッチされました System.String 型のオブジェクトの逆シリアル化中にエラーが発生しました。ルート レベルのデータは無効です。行 1、位置 1。
スタックトレース:
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream)
at Microsoft.Samples.ServiceBus.Messaging.BrokeredMessage.GetBody[T]()
at Common.SubscriptionManager.OnReceiveMessageCompleted(IAsyncResult result)