从天蓝色服务总线订阅中收到对象时出现此错误。
System.Runtime.Serialization.dll中发生了'System.Runtime.Serialization.SerializationException'类型的异常,但未在用户代码中处理
我尝试了一些反序列化代码但没有任何作用。
这就是我发送邮件的方式。请告诉我如何收到它。
public void SendMessage()
{
BrokeredMessage message = new BrokeredMessage(new TestMessage() {
MsgNumber = 1, MsgContent = "testing message" }, new DataContractSerializer(typeof(TestMessage)));
// Send message to the topic
TopicClient topicClient = TopicClient.CreateFromConnectionString(cn, topicNamespace);
topicClient.Send(message);
}
public string ReceiveMessage(){
//??????
}
答案 0 :(得分:1)
要接收单条消息,您需要获取SubscriptionClient
:
public void ReceiveMessage(string connectionString, string topicPath, string subscriptionName)
{
var subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, topicPath, subscriptionName);
var brokeredMessage = subscriptionClient.Receive();
var message = brokeredMessage.GetBody<TestMessage>();
}