Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to submit a brokeredmessage using the REST API

According to MSDN a Brokered Message can be submitted via the REST API and this brokered message can have the Properties key value pair as part of the message. I have been able to submit a Brokered message but when I recieve it the Properties field on the message is not populated. I must be encoding the Properties JSON incorrectly.

Here is the code snippet

        WebClient webClient = new WebClient();
        webClient.Headers[HttpRequestHeader.Authorization] = _token;
        webClient.Headers["Content-Type"] = "application/atom+xml;type=entry;charset=utf-8";
        Guid messageId = Guid.NewGuid();
        webClient.Headers["BrokerProperties"] = @"{""MessageId"": ""{" + messageId.ToString("N") + @"}"", ""TimeToLive"" : 900, ""Properties"": [{""Key"" : ""ProjectId"", ""Value"" : """ + message.ProjectId + @"""}]}";

        // Serialize the message
        MemoryStream ms = new MemoryStream();
        DataContractSerializer ser = new DataContractSerializer(typeof(RespondentCommitMessage));
        ser.WriteObject(ms, message);
        byte[] array = ms.ToArray();
        ms.Close();

        byte[] response = webClient.UploadData(fullAddress, "POST", array);
        string responseStr = Encoding.UTF8.GetString(response);

Does anyone have an example of submitting a BrokeredMessage using the BrokerProperties HTTP Header?

like image 966
user599084 Avatar asked Oct 17 '11 03:10

user599084


1 Answers

It looks like the servicebus team has put up some silverlight and windows phone service bus samples on codeplex at http://servicebus.codeplex.com/. I quickly looked at the code for the silverlight chat sample and it appears to have all I need to publish brokered messages via the RESTFull API.

like image 173
user599084 Avatar answered Oct 10 '22 04:10

user599084