0

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.

Amor
  • 8,325
  • 2
  • 19
  • 21
TechGuru
  • 399
  • 8
  • 20
  • Do you mean that calling the service results in a message on the queue, or should the consumer of the service put the result on the queue? If the last one is the one you're looking for, you're going to have to create a client that connects to Service Bus as well. – rickvdbosch Aug 30 '17 at 06:48

1 Answers1

0

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;
}
Amor
  • 8,325
  • 2
  • 19
  • 21