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

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

0
0
Hi omnamasivaya,

If you're wondering how to handle .NET exceptions in script code, here's one way:
engine.AddHostType(typeof(WebClient));
engine.AddHostType(typeof(Console));
engine.Execute(@"
    client = new WebClient();
    try {
        ret = client.DownloadString('http://example.com');
    }
    catch (ex) {
        if (ex.hostException) {
            Console.WriteLine(ex.hostException.GetBaseException().Message);
        }
    }
");
Note that this works only in V8ScriptEngine. An alternative that works with other script engines is HostFunctions.tryCatch; you can download the latest API reference here.

Both features are new in ClearScript 5.4, but if you're stuck with an older version, it should be fairly easy to code up your own version of tryCatch. You can see ClearScript's implementation here.

Good luck!

Viewing all articles
Browse latest Browse all 2297