2

We are converting an app from using MSMQ to Azure Service Bus. We have an object (message, type of) that looks like this:

[Serializable]
public class LeadSubmissionMessage
{
    public long LeadId { get; set; }
    public long UserId { get; set; }
    public DateTime DateTime { get; set; }
}

In creating a BrokeredMessage from the object, at first I figured it was working because it compiled and didn't throw a runtime error, but then no messages were showing up in the service bus. So when I watched it in debug, I realized it's not actually serializing the object.

BrokeredMessage brokeredMessage = new BrokeredMessage(message); 

enter image description here

In looking at other similar posts, I tried this:

BrokeredMessage brokeredMessage = new BrokeredMessage(message, new DataContractSerializer(typeof(LeadSubmissionMessage)));  

But that gets the same result.

What do I need to do so that the object actually becomes an xml string that is submitted to the message?

EDIT:

Tried this too. Same result:

[DataContract]
[Serializable]
public class LeadSubmissionMessage
{
    [DataMember]
    public long LeadId { get; set; }
    [DataMember]
    public long UserId { get; set; }
    [DataMember]
    public DateTime DateTime { get; set; }
}

2 Answers 2

1

I define the class like this:

[DataContract]
[Serializable]
public class EventMessageDto
{
    [DataMember]
    public Guid EventId { get; set; }

    [DataMember]
    public string EventType { get; set; }

    [DataMember]
    public string EventData { get; set; }
}

and the message gets created with this:

var message = new BrokeredMessage(eventMessageDto, new DataContractSerializer(typeof(EventMessageDto)));

I am using this nuget package: WindowsAzure.ServiceBus.3.3.1

1
  • 1
    Thanks Daniel! It's been too long and I don't recall the details of this problem anymore or how I got it solved. But I'm glad you found a solution and got it working, and thank you for adding your answer. Apr 17, 2019 at 14:24
0

You need to decorate your message class with [DataContract] and each property you want to be sent with [DataMember]

2
  • See edit above. Is this what you mean? I tried it, but I got the same result. Dec 23, 2015 at 14:10
  • @CaseyCrookston yes, this is what I meant. If you are still not getting your message delivered, the problem might be somewhere else, not with serialization. The fact that debugger can't show certain properties of the sent message is expected - DeliveryCount and such will only be initialized on receive. What if you just sent a string, not your message class - does it go somewhere? Dec 23, 2015 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.