473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

comunication between JScript and C#

Hello,
I have a problem of communication between JScript and C#. I must say
that I'm new to both.
In a JS file I have to call a C# function.
In particular I have:

public function Eval(expr : String) : String
{
return eval(expr);
}

And I want to call:

Eval("MyNS.myFunction()");

where myFunction is declared in a C# file, under the namespace MyNS,
and returns a string.

Is it possible to do such a thing without to consider COM objects
(which I've heard to be used in similar problems)?

Note that the .js file is generated dinamically by a CodeDomProvider in
C#.
It is compiled by adding the reference of the .exe file, which contains
myfunction():
parameters.ReferencedAssemblies.Add("MyApp.exe");
So the call Eval("MyNS.myFunction()"); will be done with Reflection

One more question: is there another way to use the jscript function
eval in C#? Maybe compiling a .js module (not dinamically and not using
reflection) that can be used by a C# module?

Thank you.

Alessandro

Jan 11 '07 #1
3 4225
Hello bowser,

Several ways
1) AJAX. There are several implementaion of it - from Microsoft and other
companies
2) Client Callback features: http://dotnetjunkies.com/Tutorial/E8...0EECF13D7.dcik

Google to find out more examples
For example see there http://www.codeproject.com/aspnet/Al...eScripting.asp

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

bHello,
bI have a problem of communication between JScript and C#. I must say
bthat I'm new to both.
bIn a JS file I have to call a C# function.
bIn particular I have:
bpublic function Eval(expr : String) : String
b{
breturn eval(expr);
b}
bAnd I want to call:
b>
bEval("MyNS.myFunction()");
b>
bwhere myFunction is declared in a C# file, under the namespace MyNS,
band returns a string.
b>
bIs it possible to do such a thing without to consider COM objects
b(which I've heard to be used in similar problems)?
b>
bNote that the .js file is generated dinamically by a CodeDomProvider
bin
bC#.
bIt is compiled by adding the reference of the .exe file, which
bcontains
bmyfunction():
bparameters.ReferencedAssemblies.Add("MyApp.exe");
bSo the call Eval("MyNS.myFunction()"); will be done with Reflection
bOne more question: is there another way to use the jscript function
beval in C#? Maybe compiling a .js module (not dinamically and not
busing reflection) that can be used by a C# module?
b>
bThank you.
b>
bAlessandro
b>
Jan 11 '07 #2

"bowser" <al****************@gmail.comwrote in message
news:11**********************@o58g2000hsb.googlegr oups.com...
Hello,
I have a problem of communication between JScript and C#. I must say
that I'm new to both.
In a JS file I have to call a C# function.
In particular I have:

public function Eval(expr : String) : String
{
return eval(expr);
}
That's not JavaScript/JScript/ECMAScript/whaddevayacallit... are you using
JScript.NET? JScript.NET should be able to call directly into any .NET
Assembly.
>
And I want to call:

Eval("MyNS.myFunction()");

where myFunction is declared in a C# file, under the namespace MyNS,
and returns a string.
Err, C# functions can't be loose in a namespace. You need a class name in
there somewhere.
>
Is it possible to do such a thing without to consider COM objects
(which I've heard to be used in similar problems)?

Note that the .js file is generated dinamically by a CodeDomProvider in
C#.
It is compiled by adding the reference of the .exe file, which contains
myfunction():
parameters.ReferencedAssemblies.Add("MyApp.exe");
So the call Eval("MyNS.myFunction()"); will be done with Reflection
If you have a metadata reference, why use Eval at all? With a reference the
JScript.NET compiler knows about MyNS and you can directly do:
var result = MyNS.MyClass.myFunction();
with no eval call
>
One more question: is there another way to use the jscript function
eval in C#? Maybe compiling a .js module (not dinamically and not using
reflection) that can be used by a C# module?
There's Microsoft.JScript.Eval.JScriptEvaluate method, but documentation is
really bad. You'd have to disassemble it to find out if it's useful to you.
>
Thank you.

Alessandro

Jan 11 '07 #3
"bowser" <al****************@gmail.comwrote in message
news:11**********************@o58g2000hsb.googlegr oups.com...
Hello,
I have a problem of communication between JScript and C#. I must say
that I'm new to both.
In a JS file I have to call a C# function.
In particular I have:

public function Eval(expr : String) : String
{
return eval(expr);
}

And I want to call:

Eval("MyNS.myFunction()");

where myFunction is declared in a C# file, under the namespace MyNS,
and returns a string.

Is it possible to do such a thing without to consider COM objects
(which I've heard to be used in similar problems)?

Note that the .js file is generated dinamically by a CodeDomProvider in
C#.
It is compiled by adding the reference of the .exe file, which contains
myfunction():
parameters.ReferencedAssemblies.Add("MyApp.exe");
So the call Eval("MyNS.myFunction()"); will be done with Reflection

One more question: is there another way to use the jscript function
eval in C#? Maybe compiling a .js module (not dinamically and not using
reflection) that can be used by a C# module?

Thank you.

Alessandro

Sure it's possible, both are managed code languages so interop is just a matter of importing
and referencing the correct assembly.

Here is a small sample.
1 is a CS file with a simple calls and method that returns a string.
2 is a js file that calls the CS method using eval.

// cstest.cs - compile as library
using System;
namespace MyNamespace
{
public class Foo
{
public string Bar()
{
return "Hello JS";
}
}
}

// test.js - compile as exe
// add a reference to cstest.dll
// command line compile jsc /t:exe /r:cstest.dll test.js

import MyNamespace;

var o : JSApp = new JSApp();
o.DoEval();

class JSApp
{
function DoEval()
{
var f : Foo;
var s : String
eval("f = new Foo;");
eval("s = f.Bar();"); // call Foo.Bar
print(s);
}
};

Hope this helps you to get started.

Willy.

Jan 11 '07 #4

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

Similar topics

6
by: Zunbeltz Izaola | last post by:
Hi, I have the following problem. I'm developing a GUI program (wxPython). This program has to comunicate (TCP) whit other program that controls a laboratory machine to do a measurement. I...
20
by: Harag | last post by:
Hi All. I'm stating out doing some web developing. I was wondering which of the server side languages should I concentrate on and learn. I Know CSS, HTML, T-SQL I can look at the client...
4
by: Harag | last post by:
Hi All I currently thinking of converting from my little knowledge of VBscript to jScript ASP. With this in mind I'm looking at my current code to see how it will convert over to Jscript. ...
6
by: RFS666 | last post by:
Hello, After I posted yesterday "using C# class in jscript", I have a new problem: I have a C# class - DBResult - that contains (and other variables) a string array (and other variables), that...
0
by: zunbeltz | last post by:
Hi, I'am writing a program to cotrol a machine. I use socket comunication (TCP) to do it. I do a measurement in my machine like this: def DoMeasurement(): setup1() setup2() while...
5
by: Maxwell2006 | last post by:
Hi, I have a requirement to develop an application component using only Server-Side Jscript (not Jscript.NET). What is Server-Side Jscript?
11
by: Olie | last post by:
This post is realy to get some opinions on the best way of getting fast comunication between multiple applications. I have scowered the web for imformation on this subject and have just found...
2
by: findyasir | last post by:
Hi all, I am having problem comunication with serial port in linux. I have tested the serial port with attaching a serial modem and dialing the numbers with wvdial. it works okie but when i...
2
by: vhm | last post by:
Hi all, I have to debug a hardware that comunicate with the computer through a USB conection. I know that the harware present some problem when the driver send some type of command to it. I'll like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.