Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: how to call webservice method & read the response

$
0
0
Hi,
we are using clearscript 5.4.7 version and trying the below
  1. Call a webservice (.svc) method by passing few parameters
  2. Get the response returned by webservice - success response
  3. Get the response returned by webservice - failure response - e.g. timeout happened
    Unable to read the response what the webservice return.
    we are trying with the below sample code in 5.4.7. Based on this working we need use the same script in 5.3.10 version. Will it work or we need to upgrade to latest ver of 5.4.7?

sample-code-snippet:

public class Console
{
    public void Log(string msg)
    {
        Console.WriteLine(msg);
    }
}
-----------
public class MyObject
{
    public string _url;
    public string data1;
    public string data2;
}
------------
    static void Main(string[] args)
    {
        using (var _eng = new V8ScriptEngine())
        {
            Console _log = new Console();

            _eng.AddHostType("Console", typeof(Console));

            MyObject _obj = new MyObject();
            _obj._url = "http://1.2.3.4/myWebService/myService1.svc/Process?param1=value1&param2=value";
            _obj.data1 = "some test data-1";
            _obj.data2 = "some test data-2";

            _eng.AddHostType("WebClient", typeof(WebClient));
            _eng.AddHostObject("jsObject", _obj);
            _eng.AddHostObject("Console", _log);

            //--.js
            _eng.Execute(@"
            var client = new WebClient();
            var ret = client.DownloadString(jsObject._url);
            Console.Log('URL return string :' + ret);
            ");

            _log.Log(" WS return val:" + engine.Script.html);

        }
    }
any help?

Thanks & Regards

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>