我在尝试解析订阅 Azure 服务总线主题时收到的消息时收到序列化异常。有人看到我错过了什么吗?我将 Microsoft.ServiceBus.Samples.Messaging 用于 Silverlight 代码。
我有一个带有以下代码的网络服务:
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)