Consuming REST services in OpenSpan

This topic is about consuming REST web services in OpenSpan.

Problem Statement
Process to be automated involves REST service calls to retrieve data from a website.
OpenSpan only supports WSDL services and therefore calls for creating a custom component that can be integrated with OpenSpan.

Solution
Creation of C# based custom component that takes 3 parameters namely URL, Method and Body
and output the JSON string result. This result can be further parsed by converting it into XML and later on iterating through the required nodes.


Automation Logic


Calling Rest Web Service via C#
public void CreateObject(string _URL, string _BODY, string _method, out string response)
{
string URL = _URL.Trim();
string DATA = _BODY.Trim();
response=string.Empty;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.Method = _method;
            request.ContentType = "application/json";
            request.ContentLength = DATA.Length;
            using (Stream webStream = request.GetRequestStream())
            using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
            {
                requestWriter.Write(DATA);
            }
try
            {
                WebResponse webResponse = request.GetResponse();
                using (Stream webStream = webResponse.GetResponseStream())
                {
                    if (webStream != null)
                    {
                        using (StreamReader responseReader = new StreamReader(webStream))
                        {
                            response = responseReader.ReadToEnd();
                         }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
}

Converting JSON string into XML

Namespace Required: 
using Newtonsoft.Json;

public string ConvertJsonToXML(string json)
{
XNode node = JsonConvert.DeserializeXNode(json, "Root");
return node.ToString();
}

Comments

  1. Good post! Thanks for sharing this Information.The information you Provided is much useful onopenspan online classes

    ReplyDelete
  2. I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.Online training in USA

    ReplyDelete
  3. Thanks for sharing this Blog. It was nice to read.RPA Training in Irving

    ReplyDelete
  4. Hello all !! You may be way behind if you are not learning RPA, enroll here for the course: https://bit.ly/2NAxcMd

    ReplyDelete
  5. Very good post about Robotic process Automation (RPA) . The information you provided in the post is very helpful and useful. Keep posting.

    Cheers
    RPA Training in Chennai\

    ReplyDelete
  6. It's really a nice experience to read your post. Thank you for sharing this useful information. If you are looking for more about Business Intelligence, Big Data Management, big data consulting services then kindly just move to http://muoro.io/

    ReplyDelete
  7. Hi Sir, I am regular to your site.
    Can you please update few more topics in ur freetime.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. If you're looking for regular updates on .net programming tech and Robotics process automation,you could keep a watch on websites like http://www.dotnetbasic.com

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. If you're looking for regular updates on .net programming tech and Robotics process automation,you could keep a watch on below website.
    Complete Dot net and RPA tutorials

    ReplyDelete
  12. Thanks for nice article you shared.
    Complete Dot net and RPA tutorials

    ReplyDelete
  13. Thank u for sharing information...this blog is really informative and useful for us...please keep it up..for more information please visit
    https://www.kausalvikash.in/blog/cognitive-rpa-and-the-need-for-the-change/

    ReplyDelete
  14. It should be noted that whilst ordering papers for sale at paper writing service, you can get unkind attitude. In case you feel that the bureau is trying to cheat you, don't buy term paper from it. security company

    ReplyDelete
  15. nice article thank you for sharing this article for more information in rpa online training visit www.jayitsolutions.com

    ReplyDelete

Post a Comment