Currently I'm involved in a project using c# . I know some of the features of this project can be easily implemented using Javascript (I have been a js developer for some time, but totally new to c#). so I'm very eager to know if it is possible to reuse the available js code in the project, or put it another way, embeded js into c# .
thanks in advance.
I think you're asking if it is possible to run JavaScript on the CLR. Similar to Java 6's JVM script engine.
EcmaScript.net could be your best bet - http://code.google.com/p/ecmascript-net/ - see also this question - Are there any .NET CLR/DLR implementations of ECMAScript?
There is an extensive article written on how to embed Javascript within C# here. Is that what you are looking for?
Are you referring to ClientScriptManager RegisterClientScriptBlock Method
There is no reason you cant continue to use existing client side javascript code.
There is a still a clear distinction to whats required on the client and what can be called by the client.
Various possibilities include: calling web services, making ajax calls to WebMethods and injecting javascript code into pages.
The way you write it it sounds like a giant cop-out of learning C# properly. Unless you actually mean that you want to use JavaScript for client-side control of your project, this is a no-go (and it doesn’t sounds like you meant client-side scripting).
That said, .NET actually allows you to mix assemblies from different languages effortlessly, but this only applies to .NET languages which can be compiled to .NET IL (bytecode) and I’m not aware of a JS-to-IL-compiler.
Javascript runs in the browser, as long as it is a web project there is no problblem combining. C# code will run on the server, javascript code in the browser.
http://msdn.microsoft.com/en-us/library/aa479011.aspx
Related
We have a classic ASP application that isn't going away. We have a new marketing system that we need to access via their API (WDSL). All of their examples are in C#, which I'm trying to learn enough about today to pull this off.
I downloaded Visual Web Developer 2010 Express and have made some progress. Then I realized that I don't know if it's possible to call a C# .net routine from a classic ASP app. I'm a generalist. I know some classic ASP vbscript, some javascript, some AJAX, stuff like that. If it hasn't been necessary at my current job, then I don't know it.
Is it possible to call c# .net files from a classic ASP application? I'd love to know just this, because I'd hate to get it worked out where I can talk to the API, and then find out I can't use what I've written. Everything I've found on StackOverflow has been .net VBScript files off .asp apps. (Heh. And still have to figure out how to deploy what I've done. lol.)
If it's not possible to run C# from .asp pages, then I need to rewrite in VBScript, and I don't know how to convert C# to VBScript. If I can't run c# off .asp, any conversion utilities out there for short routines C#->VBScript? How difficult/stupid is conversion?
(The API url is in the form of https://secure.ourspiffynewmarketingapp.com/API/1.2/Service.svc?wsdl - don't know if that matters, but figured I'd say so, since I've run across some https issues on my searches.)
I've been on StackOverflow off and on for 11 hours, and I still don't know the answers to these questions.
I don't need to get the whole thing figured out tonight, but I do need to confirm that I can access the API, and since all of the examples are in C#, which I've never even LOOKED at before today, I can't even confirm that.
I couldn't find exactly how I implemented it but did find this article that is pretty much the same thing.
classic-asp-soap-request
Re : Is it possible to call c# .net files from a classic ASP application?
In order to access 'dll' (assembly code) you need to map your top level (exposed components) as COM callable wrappers, and register these as COM components. You can then use them in your ASP Classic just as any other COM component Server.CreateObject('MyProgIdGoesHere')
Have a look here if you need to call SOAP web services from ASP Classic, using the Microsoft.XMLHTTP component (from memory there might have been a server version of this as well). You will need to build up the SOAP request and parse the response yourself, however :(
Edit If you are feeling brave, you might also look at starting the conversion process from ASP Classic across to .NET.
We have C# code, which is backend for us. Now we need it to be used in our website which is developed in Drupal.
As far as I know, there is no easy way to do it. You basically have 2 options:
Rewrite the code in php. It may be not possible to do it however, it depends on what the code does.
Expose c# code as an external webservice (e.g. with WCF) and then consume the webservice. Drupal is able to do it - more info.
A sloppy solution would also be to display your C# page in the Drupal page with an iframe. I do also agree with empi's answer to rewrite the code in php or a web service depending on your requirement.
You can build DLL project (class library) in C# and use the DLL as reference back in the drupal project.
Not sure about this, and never done before.
You better research more.
But, the best way to use the .NET code in another application is to build the required code into DLL project and use in whichever language you want to use.
I am building a phonegap like solution using MonoTouch & UIWebView. I would like to expose a number of C# methods via Javascript. I know you can do this in Objective C using WebScriptObject but I can't see where/if this is exposed in the MonoTouch API's.
Is there a way to access WebScriptObject?
Is there a way to access WebScriptObject?
No, WebScriptObject is not part of MonoTouch (like it is part in MonoMac) since WebKit, as a framework, is not part of iOS.
UIWebView does allow you to evaluate JavaScript code but I'm not sure (never tried or even looked for) how you can, from there, get back into C# methods.
Just as as corollary to Sebastian's answer you can always create a simple binding that allows your UIWebView to interact with C# code via a HttpListener:
http://yobriefca.se/blog/2011/12/05/rolling-your-own-phonegap-with-monotouch/
You can also use iOS Background threads to interact with other apps via Javascript or C# using HttpListener:
http://blog.devnos.com/remember-when-apps-didnt-talk-to-each-other
As some additional side answers to this...
you can access javascriptcore - but you will have to work out the bindings for this
some people have managed to use Jint (0.9 or older - with no Reflection.Emit JIT code)
I love JavaScript. I started out coding in ActionScript and since the syntax is almost identical, I naturally understood JavaScript.
Recently, I have been learning how to use ASP.NET and MVC (which is not new to me since there are several MVC frameworks for Flash and Flex). And I'm trying to decide whether I want to learn C# or JScript... I say this ignorantly because I don't know how different JavaScript and JScript are... and C# is a completely different language all together.
What advantages does C# have over JScript?
and does it really even matter that I know and love JavaScript?
C# if only because you will be a gazillion times more employable.
If you're using ASP.NET MVC you're going to want to learn both C# and Javascript. Microsoft is now bundling jQuery, a Javascript framework, with Visual Studio and it is a great fit with ASP.NET MVC. I'd recommend using C# for the controllers and model layers, regular HTML for the view templates and then jQuery for all the client-side DOM manipulation.
Edit: Just noticed you said you already know and love Javascript. I'd just like to point out that I had never used Javascript before learning ASP.NET MVC and I found it to be a lot more similar to C# than I was expecting. Of course C# is statically typed, however the syntax has quite a few similarities.
.NET in general and ASP.NET can be written in many languages, however only two are really popular and have big pool of support and tutorials: C# and VB.NET
This alone is reason enough to choose C# over JScript IMO, and C# share lots of its syntax with JScript - surely much more than VB.NET will ever share.
So like everyone already said, go with C# and you'll be swimming in familiar water with the bonus of many lifeguards available for you and ready to jump and save you when you drown. :)
JScript is actually a script language used by Microsoft product. If you compare JScript over C#, it's somehow like you compare JavaScript with Java.
ASP.Net require full managed programming language like VB.Net or C# (I noticed that the role of Java.net is fading out, is it?), I don't think JScript is supported in most cases.
One more PLUS on C#: Learning C# isn't that hard suppose you have enough experience in OOP ActionScript. They share quite a number of common syntax, and quite importantly, most tutorials and resources out there about .Net is written in C#.
I'd like to host Javascript in my C# program. I would like to allow users to write custom Javascript code, and have my C# program run their functions, as well as allow the users to use my framework code.
Is it possible to do this? If so, how?
Edit: To be clear, I am not using ASP.NET for this project.
you can also use a webbrowser control to host the javascript in a html document, to interact between the two you would make a COM visible class and set an instance of it to the ObjectForScripting property.
Any public members of the 'external' class are now accessible through window.external in javascript. Also, from the managed code side you can use the InvokeScript method of the document to call any javascript functions.
This way it is easy to pass complex objects between the two.
I used this idea quite a bit in this Google Earth Api application.
http://fraserchapman.blogspot.com/2008/08/google-earth-plug-in-and-c.html
I'd highly recommend you use the Microsoft Dynamic Langauage Runtime (DLR). It's purpose in life is to facilitate scripting in a .Net environment. The DLR is not script specific so over time more script languages will be built on top of it but at the moment the ones I know about are IronRuby, IronPython and JScript.
Spidermonkey .NET Is probably what you are looking for.
I'm not sure how developed it is. Buts its basically a port of Mozilla's Spidermonkey Javascript parser engine which I like a lot.
Or you can evaluate it directly
The way to do this used to be the Windows Script Host, which permitted you to host either JSCript or VBScript.
You can certainly run Javascript natively from C# - see this article for a starter. Having the Javascript access your framework could be tricker, though. Perhaps Script# could help?
There are HTML components where you can embed JavaScript. For the other way the proper thing is an ASP.NET web service. Perhaps with a smart client you can combine both.