ASP.NET Web应用程序和C#应用程序之间的双向通信

ASP.NET Web应用程序和C#应用程序之间的双向通信

问题描述:

我需要建立一个网站和一个应用程序,沟通起来,在两个方向。我将使用ASP.NET网站,并在C#应用程序。

I need to build a website and an application that communicate together, in both directions. I will be building the website with ASP.NET, and the application in C#.

我会主办的网站自己,它将在同一台机器上应用程序运行。

I will be hosting the website myself, and it will be running on the same machine as the application.

我不知道有什么用两者之间发送数据的最佳技术。在C#应用程序将需要运行所有的时间。我应该建立一个C#控制台应用程序,然后隐藏控制台窗口?或者将一些其他类型的应用程序更合适?

I don't know what's the best technique to use to send data between the two. The C# app will need to be running all the time. Should I build a C# Console App, and then hide the console window? Or would some other kind of app be more appropriate?

我一直期待一轮网络找几个不同的建议,包括套接字,消息队列,远程处理和WCF。有几个三分球将是非常美联社preciated - 我是新来的这一切

I've been looking round the Web and found several different suggestions, including Sockets, Message Queues, Remoting and WCF. A few pointers would be much appreciated - I'm new to all of this.

感谢您。

修改请求 - 响应模式将被使用,Web应用程序总是被一个实例的请求。这就是我的意思是通过双向通信。

EDIT The request-response pattern will be used, with the Web App always being the one instantiating the requests. This is what I meant by two-way communication.

Web应用程序将发送到后端应用程序的请求,后端应用程序将进行一些处理,然后发送一个响应返回给Web应用程序。 JSON将用于数据发送来来回回。

The web app will send a request to the back-end app, the back-end app will perform some processing, and then send a response back to the web app. JSON will be used to send data to and fro.

我将使用SQL Server防爆preSS 2008 R2,以及后端的应用程序将是唯一一个与数据库进行通信。 Web应用程序将主要以presentation层的关注。

I will be using SQL Server Express 2008 R2, and the back-end app will be the only one communicating with the database. The web app will mostly be concerned with the Presentation Layer.

后端应用程序将在应用程序启动(从数据库加载的数据),这些实例在内存中的对象,然后坚持到DB(执行过程中和结束之前)。将一个C#控制台应用程序是非常适合这种事情?

The back-end app will have in-memory objects that are instantiated when the app is started (with data loaded from the DB), and then persisted to the DB (during execution and before closing). Will a C# Console App be ideal for this kind of thing?

您在您的评论描述的是典型的三层应用程序。

What you describe in your comment is typical three-tier application.


  • 前端:在IIS托管ASP.NET应用程序

  • 后端:运行的 Windows服务 .NET应用程序(或WCF在IIS中托管的应用程序/ WAS)与暴露的Web服务。前端应用程序使用Web服务这个应用程序(或远程)进行通信。

  • 数据库:只能通过后端应用程序访问

  • Front-end: ASP.NET application hosted in IIS
  • Back-end: .NET application running as Windows service (or WCF application hosted in IIS/WAS) with exposed web services. Front-end application communicates with this application using web services (or remoting).
  • Database: Accessed only by Back-end application.

只是为了说清楚。双向有很多含义,但在这种情况下常见的是前端使得调用后端和后端响应(请求 - 响应模式)。后端永远不会调用前端 - 这样的沟通是非常难以实现与ASP.NET应用程序

Just to make it clear. Two-way has many meanings but common in this scenarios is that front-end makes call to back-end and back-end respond (request-response pattern). Back-end never calls front-end - such communication is very hardly achievable with ASP.NET application.

ASP.NET工作在每个请求的基础。客户端调用ASP.NET应用程序,并有客户端请求的处理=这就是所有的逻辑运行。当该请求被处理时,处理结束。所以从调用后端的ASP.NET应用程序,除非你揭露一些特殊的Web服务的后端处理,但即使它不会与客户相关要求处理,而不在ASP.NET一些内部状态保持不适合这个应用。

ASP.NET works on per request basis. Client calls your ASP.NET application and there is processing of the client request = that's where all logic runs. When the request is processed, the processing ends. So calling your ASP.NET application from back-end doesn't fit this unless you expose some special web service for back-end processing but even after that it will not correlate with your clients request processing without some internal state hold in ASP.NET application.