How to send WCF Response to Azure queue

110 views Asked by At

I have recently started working with Azure service bus. I am able to send and receive messages from queue using my console application and able to consume one WCF Service in my console app and then sending responses to azure queue. But i have some different scenario. I don't want to create any console application as i want to send response(to azure queue) using SOAPUI. I will host the service on IIS and by requesting through SoapUI, i should get response in my queue. Please suggest some solution for this. Any help will be appreciated.

1

There are 1 answers

0
Amor On

I suggest you add a extra parameter to the service method. You could pass 'true' from the SoapUI to save the result to storage queue. Code below is for your reference.

public CompositeType GetDataUsingDataContract(CompositeType requestData, bool saveResultToQueue = false)
{
    //Process the request data and get the result
    CompositeType result = GetResult(requestData);
    if (saveResultToQueue)
    {
        //Serialize the result to a string
        XmlSerializer serializer = new XmlSerializer(typeof(CompositeType));
        MemoryStream ms = new MemoryStream();
        serializer.Serialize(ms, result);

        string serilizedResult = string.Empty;

        using (StreamReader sr = new StreamReader(ms))
        {
            serilizedResult = sr.ReadToEnd();
        }

        //Add a new message to the queue
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageConnectionString");
        CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
        CloudQueue queue = queueClient.GetQueueReference("myqueue");
        queue.CreateIfNotExists();
        CloudQueueMessage message = new CloudQueueMessage(serilizedResult);
        queue.AddMessage(message);
    }
    return result;
}