简体   繁体   English

使用Javascript和C#连接服务器和客户端

[英]Connecting Server and Client with Javascript and C#

I need to create a web page that gets data from an SQL database, and can run certain executables (that have already been written from previous projects).The code to retrieve data from SQL was written in C#, as it was used previously with ASP.NET. 我需要创建一个网页来从SQL数据库获取数据,并且可以运行某些可执行文件(已经从以前的项目中编写过)。从SQL中检索数据的代码是用C#编写的,因为以前与ASP一起使用过。 。净。 Is it possible to reuse all of this code the way it is with my current application (using Angular)? 是否有可能像当前应用程序(使用Angular)那样重用所有这些代码?

How to set up the server side? 如何设置服务器端? I know I probably have to create a web server, and then use "get" and "post" requests from the client side, am I on the right track. 我知道我可能必须创建一个Web服务器,然后使用客户端的“ get”和“ post”请求,这是否正确? Can JavaScript client side communicate with a C#-written server side? JavaScript客户端可以与C#编写的服务器端进行通信吗?

Unequivocally yes , you can have a JavaScript frontend communicate with a C# backend. 毫无疑问, 是的 ,您可以让一个JavaScript前端与C#后端进行通信。 There are two primary MS provided technologies that can be used: 可以使用两种主要的MS提供的技术:

  • ASP.NET WebAPI ASP.NET WebAPI
  • SignalR SignalR

And lots of 3rd party ones (like Nancy). 还有很多第三方(例如南希)。

WebAPI is a simple HTTP server typically used to build RESTful backends. WebAPI是一个简单的HTTP服务器,通常用于构建RESTful后端。 Given your description its probably what you want to use. 根据您的描述,它可能是您想要使用的。

SignalR is a protocol for "push" applications (though it can be used for server invocations). SignalR是用于“推送”应用程序的协议(尽管它可用于服务器调用)。 If you don't need to call client-side code its a bit overkill. 如果您不需要调用客户端代码,则可能有点过头了。

On the client side, if using WebAPI or similar on the backend, you just do HTTP requests as you would against any standard API. 在客户端,如果在后端使用WebAPI或类似的资源,则只需对任何标准API进行HTTP请求即可。 For AngularJS that's done with the $http service, for Angular (2+) that's Http and for 4+ HttpClient . 对于使用$http服务完成的AngularJS,对于使用Http Angular(2+),对于使用4+的HttpClient

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#服务器数组到客户端/ javascript - C# server array to client / javascript 在客户端和服务器之间传输日期时间的最佳方式(c#/javascript) - Best way to transfer datetimes between client and server (c# / javascript) 授权集成到客户端 - 服务器应用程序(C#,JavaScript) - Authorization integration into client-server app (C#, JavaScript) 如何将字典从C#(服务器)传递到javascript(客户端) - How to pass Dictionary from c#(server) to javascript(client) 使用javascript聊天客户端(jsjac)连接到远程jabber服务器 - Connecting to a remote jabber server with a javascript chat client (jsjac) javascript和C#服务器通信 - javascript and C# server communication RC4算法:在客户端使用Javascript和服务器c#的情况下无法加密/解密数据 - RC4 Algorithm: Unable to Encrypt / Decrypt data where client uses Javascript and Server c# 使用JavaScript在C#中使用邮件附件在客户端计算机上获取服务器端导出的Crystal报表路径 - Get server side exported crystal report path on client machine using javascript for mail attachment in c# 获取在 javascript 的客户端上创建的图像(例如 svg),返回到 c# 的服务器端 - Getting an image (eg svg) created on the client in javascript, back to the server side for c# 如何在客户端(使用javascript)和服务器端验证mac地址和ipaddress(使用c#) - How to Validate mac address & ipaddress in client side(using javascript) & server side(using c#)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM