从javascript调用c#库 [英] calling c# library from javascript

查看:83
本文介绍了从javascript调用c#库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个用C#编写的类库.使用该库,我正在执行所有逻辑任务,并执行数据库粗操作.我有一个限制,我不能使用.aspx页面.我只允许使用html和javasript构建我的ui(可以使用javascript框架,例如jquery,moo).

请让我知道如何使用html和javasript ui使用我的库.

谢谢,

Hi,
I have a class library written in c#. using this library i am doing all my logical task and databaes crude operation. I have a restriction that, i cannot use .aspx page. i am only allowed to build my ui using html and javasript(can use javascript framework like jquery, moo).

Please let me know how can i use my library using html and javasript ui.

Thanks,

推荐答案

基本上,您不能直接这样做.当您说"JavaScript"时,它表示客户端".如果您甚至不知道您的用户运行的是Windows还是安装了任何CLR实现的任何软件(Mono或其他版本),该怎么办?

严格来说,术语呼叫"仅适用于相同的线程和相同的应用程序域.当JavaScript在某个Web服务器上运行时,您甚至都不知道是哪个服务器,因此根本无法谈论对任何托管代码的调用".但是,让我们多谈一点...

您可以在服务器端使用代码.当然,在这种情况下,您不会调用"它,但是JavaScript会通过提交一种AJAX形式来生成HTTP请求-这就是它所能做的.但是,由于您不使用ASP.NET(我对您了解吗?),那么您将在何处托管它?因此,如果我们同意将调用"的概念扩展到HTTP请求(在某种意义上类似于术语RPC(远程过程调用")之一),则您的问题将减少为以下一种:您需要使用HTTP服务器上的C#库,但您不能使用ASP.NET,因此-使用CLS开发自己的HTTP服务器端技术并替换ASP.NET,从原理上讲,这是完全有可能的.在最简单的解决方案中,创建您自己的HTTP服务器.是的,认真.

抱歉,我怀疑您不太了解服务器和客户端的功能.而且您也不会激发您的需求.坦率地说,对于Web应用程序使用C#而不使用ASP.NET听起来有点荒谬.

—SA
Basically, you cannot, not directly. When you say "JavaScript" it means "client side". What "C# library" if you don''t even know if your user runs Windows or anything which has any CLR implementation installed (Mono or whatever)?

Strictly speaking, the term "call" is applicable only to the same thread and the same Application Domain. As JavaScript runs on some Web server, you don''t even know which one, you cannot talk about a "call" to any managed code at all. But, let''s talk a bit more…

You can use your code on server side; in this case you would not "call" it, of course, but JavaScript would generate HTTP request by submitting a form of AJAX — that''s all it can do. But as you''re not using ASP.NET (did I understand you right?), so where would you host it? So, if we agree to expand the notion of "call" to HTTP requests (in the sense similar to the one of the term RPC ("Remote Procedure Call"), your problem would be reduced to the following one: you need to use C# library on HTTP server but you cannot use ASP.NET, so — develop your own HTTP server-side technology using CLS and replacing ASP.NET. Well, in principle it is quite possible. On of the simplest solutions — create your own HTTP server. Yes, seriously.

Sorry, I suspect you don''t really understand what server and client part do. And you also don''t motivate your requirements. Using C# for Web application and not using ASP.NET sounds a bit of absurd, frankly.

—SA


这篇关于从javascript调用c#库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆