473,503 Members | 1,712 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(10, 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 2096
Hi,

go****@insightfulmes.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(10, 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...@bluewin.ch>
wrote:
Hi,

goo...@insightfulmes.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(10, 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...@bluewin.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(inExpression);
}

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(inExpression);
}

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(inExpression);
}
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...@bluewin.ch>
wrote:
Hi again,
public float Eval (string inExpression)
{
return eval(inExpression);
}

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
4242
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...
13
2809
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,...
20
1703
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...
1
4984
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...
15
2118
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...
5
1898
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. ...
7
2571
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...
1
1759
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. ...
3
3470
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...
0
7084
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...
0
7278
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,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
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...
0
4672
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...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.