473,651 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.myFu nction()");

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.Refe rencedAssemblie s.Add("MyApp.ex e");
So the call Eval("MyNS.myFu nction()"); 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 4240
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.myF unction()");
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.Ref erencedAssembli es.Add("MyApp.e xe");
bSo the call Eval("MyNS.myFu nction()"); 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.comw rote in message
news:11******** **************@ o58g2000hsb.goo glegroups.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/whaddevayacalli t... are you using
JScript.NET? JScript.NET should be able to call directly into any .NET
Assembly.
>
And I want to call:

Eval("MyNS.myFu nction()");

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.Refe rencedAssemblie s.Add("MyApp.ex e");
So the call Eval("MyNS.myFu nction()"); 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.my Function();
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.JScri pt.Eval.JScript Evaluate 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.comw rote in message
news:11******** **************@ o58g2000hsb.goo glegroups.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.myFu nction()");

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.Refe rencedAssemblie s.Add("MyApp.ex e");
So the call Eval("MyNS.myFu nction()"); 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
2931
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 have a dialog box, wiht two buttoms "Start measurement" and "Stop". "Start" executes a function that do the measurement in the following way.
20
5960
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 javascript code and work out what it does but I can't really write it from scratch.
4
5857
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. One thing I have spotted that I can't think of a way round is the ADO recordset.GetRows command.
6
1851
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 contains data from a database query which is done in C# in codebehind. I create a jscript - script that is injected into the aspx-page. I need this to fill an activeX-control with data. I assign the string-array (and - for testing - a single...
0
1088
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 MeasurementNotFinished():
5
1470
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
4333
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 conflicting views and far from ideal solutions. My application has to send small amounts of data about 50bytes to multiple client applications. The catch is that this has to happen about 1000 times a second. My first attempt was .net remotting...
2
6475
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 connect HSM to the serial port it sends the message but i did not get a reply. mean it always being blocked in the read function. The same hsm is working fine in unix. so there is no problem with hsm. I am using the code as given
2
3356
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 to discover what command is causing the hardware to crash. How can I intercept the comunication via USB between this hardware and the PC and record it to a file, for this to be analized later? Someone have writen a program to do that? Can someone give...
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8467
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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

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.