1
votes

I got this error upon receving an object from a subscription in azure service bus.

An exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll but was not handled in user code

I've tried some deserialization code but nothing works.

This is how I send a message. Please tell me how to receive it.

    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(){
       //??????
    }
1

1 Answers

1
votes

To receive a single message, you need to get the 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>();
}