[英]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提供的技术:
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.