[英]How to consume an object from azure service bus topic subscription
從azure服務總線中的訂閱中刪除對象時出現此錯誤。
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(){
//??????
}
要接收一條消息,您需要獲取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>();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.