473,569 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing a JavaScript command from a web service

I would like to execute a single JavaScript command from within a web
service. The command is a mathmatical statement.

I have a web page with some client side logic that does this and I'm
now moving that functionality into a web service.

To clarify - on the UI the user is collecting and entering data and
then it gets stored into the database. Most fields are input but
there are some that are calculated and stored. The calculated fields
use Java Script notation. For example the data collection might have
3 parameters, user inputs P1 and P2 and then a calculated field
storing the larger value. The calculation formula would be "Math.max
($P1$, $P2$)" The dollar signs means run-time substitution.

I can perform the string manipulation to get a statement like
"Math.max(1 0, 20)". Is there a way to call java to evaluate it and
get the returned value?

The existing UI piece has been in place for a long time so there are
many expressions already specified in Java syntax.

Mike Buchanan

Feb 22 '07 #1
7 2101
Hi,

go****@insightf ulmes.com wrote:
I would like to execute a single JavaScript command from within a web
service. The command is a mathmatical statement.

I have a web page with some client side logic that does this and I'm
now moving that functionality into a web service.

To clarify - on the UI the user is collecting and entering data and
then it gets stored into the database. Most fields are input but
there are some that are calculated and stored. The calculated fields
use Java Script notation. For example the data collection might have
3 parameters, user inputs P1 and P2 and then a calculated field
storing the larger value. The calculation formula would be "Math.max
($P1$, $P2$)" The dollar signs means run-time substitution.

I can perform the string manipulation to get a statement like
"Math.max(1 0, 20)". Is there a way to call java to evaluate it and
get the returned value?

The existing UI piece has been in place for a long time so there are
many expressions already specified in Java syntax.

Mike Buchanan
First, let me precise that Java has nothing to do with JavaScript (or as
much as a car had to do with a carpet).

That said, your calculation was working on the client until now. Putting
it in a web service means moving it to the server. I assume that you use
ASP.NET?

ASP.NET allows programming in JScript.NET, which has an "eval" method
that you can use for this kind of purposes. A colleague of mine does
this and it works fine. So you can program your web service in
JScript.NET, or program it in C# and link to a JScript.NET utility
assembly which would evaluate the expression and return the result.

HTH
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 22 '07 #2
On Feb 22, 1:49 pm, "Laurent Bugnion [MVP]" <galasoft...@bl uewin.ch>
wrote:
Hi,

goo...@insightf ulmes.com wrote:
I would like to execute a single JavaScript command from within a web
service. The command is a mathmatical statement.
I have a web page with some client side logic that does this and I'm
now moving that functionality into a web service.
To clarify - on the UI the user is collecting and entering data and
then it gets stored into the database. Most fields are input but
there are some that are calculated and stored. The calculated fields
use Java Script notation. For example the data collection might have
3 parameters, user inputs P1 and P2 and then a calculated field
storing the larger value. The calculation formula would be "Math.max
($P1$, $P2$)" The dollar signs means run-time substitution.
I can perform the string manipulation to get a statement like
"Math.max(1 0, 20)". Is there a way to call java to evaluate it and
get the returned value?
The existing UI piece has been in place for a long time so there are
many expressions already specified in Java syntax.
Mike Buchanan

First, let me precise that Java has nothing to do with JavaScript (or as
much as a car had to do with a carpet).

That said, your calculation was working on the client until now. Putting
it in a web service means moving it to the server. I assume that you use
ASP.NET?

ASP.NET allows programming in JScript.NET, which has an "eval" method
that you can use for this kind of purposes. A colleague of mine does
this and it works fine. So you can program your web service in
JScript.NET, or program it in C# and link to a JScript.NET utility
assembly which would evaluate the expression and return the result.

HTH
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog:http://www.galasoft-LB.ch
PhotoAlbum:http://www.galasoft-LB.ch/pictures
Support children in Calcutta:http://www.calcutta-espoir.ch- Hide quoted text -

- Show quoted text -
Thanks Laurent,

I don't have JScript.NET installed on my machine, but maybe I can get
it. The web service is already written in C# with this one little bit
stubbed out.

Mike Buchanan

Feb 23 '07 #3
Hi Mike,

Mike Buchanan wrote:
Thanks Laurent,

I don't have JScript.NET installed on my machine, but maybe I can get
it. The web service is already written in C# with this one little bit
stubbed out.

Mike Buchanan
The alternative would be to find a .NET JavaScript engine, but I don't
think there is one available, and honestly it would be quite overkill.
Thanks to the multi-language support in .NET, using JScript.NET for this
task seems more reasonable.

Let us know how that works out

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 23 '07 #4
On Feb 23, 1:16 am, "Laurent Bugnion [MVP]" <galasoft...@bl uewin.ch>
wrote:
Hi Mike,

Mike Buchanan wrote:
Thanks Laurent,
I don't have JScript.NET installed on my machine, but maybe I can get
it. The web service is already written in C# with this one little bit
stubbed out.
Mike Buchanan

The alternative would be to find a .NET JavaScript engine, but I don't
think there is one available, and honestly it would be quite overkill.
Thanks to the multi-language support in .NET, using JScript.NET for this
task seems more reasonable.

Let us know how that works out

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog:http://www.galasoft-LB.ch
PhotoAlbum:http://www.galasoft-LB.ch/pictures
Support children in Calcutta:http://www.calcutta-espoir.ch
I'm using Visual Studio 2003. I found JSharp.NET, is that what you
mean?

I installed it but without any Java experience or a text book I
haven't gotten very far.

I looked around for the "eval" method but didn't see it in the
language.

What I want *seems* pretty simple, a class with one public method that
takes a JavaScript numeric expression as a string, evaluates it and
returns a number. If I could find the "eval" function then it would
be something like:

public float Eval (string inExpression)
{
return eval(inExpressi on);
}

Mike Buchanan

Feb 24 '07 #5
Hi,

Mike Buchanan wrote:
I'm using Visual Studio 2003. I found JSharp.NET, is that what you
mean?
No, JSharp.NET is a Java-based language, and as we all know, Java has
nothing to do with JavaScript, which is what you want.
I installed it but without any Java experience or a text book I
haven't gotten very far.

I looked around for the "eval" method but didn't see it in the
language.
I looked around, and found this page, which should help you:
http://msdn2.microsoft.com/en-us/lib...5a(vs.71).aspx

The trick is that you cannot compile JScript.NET in Studio directly, you
need to compile it using the command line as explained here:
http://msdn2.microsoft.com/en-us/lib...z6(VS.71).aspx

Once compiled, you get an assembly that you should be able to reference
like a normal .NET assembly. If I have time today, I'll try and write a
small example.

HTH,
Laurent
>
What I want *seems* pretty simple, a class with one public method that
takes a JavaScript numeric expression as a string, evaluates it and
returns a number. If I could find the "eval" function then it would
be something like:

public float Eval (string inExpression)
{
return eval(inExpressi on);
}

Mike Buchanan

--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 25 '07 #6
Hi again,
>public float Eval (string inExpression)
{
return eval(inExpressi on);
}
Here is an example which should help you do what you want:

http://www.odetocode.com/Code/80.aspx

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 25 '07 #7
On Feb 25, 11:43 am, "Laurent Bugnion [MVP]" <galasoft...@bl uewin.ch>
wrote:
Hi again,
public float Eval (string inExpression)
{
return eval(inExpressi on);
}

Here is an example which should help you do what you want:

http://www.odetocode.com/Code/80.aspx

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog:http://www.galasoft-LB.ch
PhotoAlbum:http://www.galasoft-LB.ch/pictures
Support children in Calcutta:http://www.calcutta-espoir.ch
This does exactly what I want. Thanks for all your help.

Feb 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4251
by: Steve Duke | last post by:
Here is the block of the sproc that I?ve created. All lines execute fine except for the ?exec master..xp_cmdshell @reboottc?. In order to make this work from the query analyzer I had to set the MSSQLSERVER service to have the same credentials as the thin clients we are trying to shut down, that means the service is running as an...
13
2823
by: BK | last post by:
Can someone point me to a code sample that illustrates executing long running tasks (asynchronous) from a web application in ASP.NET? I assume that Web Services might come into play at some point, but I'm not sure how to get started. For example, I have an application that, upon a user initiating through a button or link click, will go out...
20
1714
by: JulioHM | last post by:
Hello, Not sure if this is the right discussion group to post this, but here it goes. For some god-forsaken reason (which I can't find out either) MSIE stopped executing any JavaScripts. In any page which contains JavaScript code, that code won't be executed. There are no error messages, no warnings, nothing. It simply does'nt work. I'm...
1
4988
by: tuckkhai | last post by:
Hi, I am a newbie in this area. I would like to know whether is it possible to execute shell command in windows service. I had install a program in the server which i would like it to be executed using windows services. Is it possible. If yes, how? Thanks
15
2124
by: Chakkaradeep | last post by:
Hi all, i have written a Service,now i want to execute another application (for eg;calc.exe) in the service....how will i perform it??... i tried using this.... /**************Executing a Process code starts here**************/ System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false;
5
1903
by: Full Name | last post by:
The question is not about writing javascript, but having it execute in a browser (IE, firefox or opera, doesn't matter). Since the last series of updates in win2K, javascript no longer executes. If I am in an admin logon, it executes fine. I have installed and uninstalled the java runtime engine several times. It seems to be a permissions...
7
2580
by: David R. | last post by:
Hello all, I would like to generate a Sql-Script-File and a Batch-File to execute the Batch-File over C#-Code and use the SQL-File as an Input-File for the command "osql" in the Batch-File. I generate the two files "attachDB.sql" and "setup.bat" with the following code: AttachAtpDBFile = File.CreateText(@"c:\attachDB.sql");...
1
1762
by: Sh0t2bts | last post by:
Hi, I am using the below command to restart a service on one of my web boxes, this runs fine from the command prompt and also through a *.bat file. "\\Server1\Applist$\BOBJCentralMS\psservice.exe" \\Server2 -u eutee-ww02p\Username -p password restart BOBJCentralMS
3
3475
by: rembi | last post by:
I am running a service (sourceforge.net/projects/statfink/ ) that pulls and displays fantasy football statistics. One of the limitations is that it only pulls stats for games that are active or completed at the time a specific button on the server is selected. This button calls a javascript function. I'm looking for a method to select that...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.