This project has moved and is read-only. For the latest updates, please go here.

How to call service method within same class

Sep 19, 2014 at 1:23 PM
I can successfully run a script, however I want to call another service via a hostfunction.
the hostfunction works within C# since it instantiates a proxy dll and reads config from web.config... but I suspect one cannot do this via clearscript?
Sep 19, 2014 at 1:55 PM

We're a bit unclear about what you mean by "hostfunction".

There are exceptions, but if you can do it in C#, you should be able to do it in script code as long as you've exposed the relevant .NET types and/or objects to the script engine. Can you provide a sample that does in C# what you'd like to do in script code?

Sep 19, 2014 at 2:12 PM

Ok this is the script code ...
            using (var engine = new  JScriptEngine())
                engine.AddHostObject("host", new RFManagerService());

                StringBuilder script = new StringBuilder();
                script.Append("function DoWork() {return host.GetCustomerInternal('ContractNo', '15405844');}");
                result = engine.Script.DoWork();
now this script is called in a function in a class that also contains the following method ... this method works from other C# code in the same class, but not from script?
        public Customer GetCustomerInternal(string searchBy, string searchVal)
            string validationMsg = string.Empty;
            //return null;
            return GetCustomer(searchBy, searchVal, out validationMsg);

        public Customer GetCustomer(string searchBy, string searchValue, out string validationMsg)
            RFWellnessEngineProxy wellnessEngineProxy = null;

            Customer customer = null;
            validationMsg = string.Empty;

                wellnessEngineProxy = new RFWellnessEngineProxy();
                if (searchBy.Equals("ContractNo") || searchBy.Equals("Contract_No"))
                    customer = wellnessEngineProxy.GetCustomerByContractNo(int.Parse(searchValue), out validationMsg);

                return customer;
            catch (Exception ex)
                //Close proxy(ies)
            return customer;
Sep 19, 2014 at 2:49 PM
Hi again,

Thanks for posting the code.

There doesn't appear to be anything wrong here. Your script calls a public method of an exposed object. What are you seeing? Does the script engine throw an exception?

Sep 19, 2014 at 3:05 PM
Edited Sep 19, 2014 at 3:05 PM
Here is the error i see ....
works when calling that method directly though ...
Sep 19, 2014 at 3:13 PM
here is a link to prove that the method does work when called directly ...
this i did just before the script attempt, and it does return a customer object. script generates socket timeouts but i do not know why
Sep 19, 2014 at 4:24 PM
Hi iwcoetzer,

At first glance socket timeouts would appear to be completely unrelated to script execution. On the other hand, you're using JScript, which is a COM component, so it may share infrastructure with WCF or one of its dependencies.

Can you post a stack trace for the innermost (first-chance) exception you're seeing?

Also, what does your setup look like? Is the service running on the same machine? What protocols or bindings are you using?

Sep 19, 2014 at 5:38 PM
Hi. services are currently all hosted on my dev box. will post innerexception when I am back behind my laptop thanks. would be nice if I can get this to work. I want the script to call that method for input parameters so that on can change the script in future to call other functions as need may arise.