接收Web请求并处理
我是 Web 应用程序领域的新手,我想知道如何部署网页并将其公开给特定方。我有一个从另一个应用程序接收短信的应用程序。我需要为其他应用程序提供一个网页,以便将消息发送到我的应用程序。
我基本上想公开 MessageReceive.aspx 页面并接收如下请求。我知道如何处理查询字符串,但不确定将页面公开给互联网上的第三方应用程序的最佳方式?
http://www.Mysite.com.au/MessageReceive.aspx?ORIGINATOR=61412345678&RECIPIENT=1987654&MESSAGE_TEXT=Hello%20There!
我是否需要将“MessageReceive.aspx”页面部署为IIS 上的 Web 应用程序?如果是这样,你能给我举个例子吗?
在 Windows 服务中使用 HttpListener 类怎么样?有能力做到这一点吗?
谢谢!
I am new to web application domain and I want to know how to deploy a web page and expose that for a particular party. I've an application that receives SMS from another application. I need to provide a web page for the other application in order to send messages to my application.
I basically want to expose MessageReceive.aspx page and receive requests like below. I know how to process query strings but not sure the best way to expose a page to a third party application on internet?
http://www.Mysite.com.au/MessageReceive.aspx?ORIGINATOR=61412345678&RECIPIENT=1987654&MESSAGE_TEXT=Hello%20There!
Do I need to deploy "MessageReceive.aspx" page as a web application on IIS? If so could you please point me an example?
How about using HttpListener class in a windows service? Is that capable of doing this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HttpListener 类确实能够托管像任何类型的应用程序(即 Windows 桌面应用程序、Windows 服务、控制台应用程序等)内的端点一样。以串行方式使用 HttpListener,一次可以处理一个请求是非常简单,但是使用它来提供任意数量的并发性很快就会变得非常复杂。
如果您确实希望在 Windows 服务中托管串行端点,那么 HttpListener 绝对是最快的方法。它真正需要的只是这样:
像这样的简单程序一次只能处理一个请求,但是 HttpListener 可以一次排队相当多的请求。如果您不打算用您的服务处理高负载,那么它应该足够了。如果您需要处理高负载并且需要并发请求处理,则需要使用 BeginGetContext/EndGetContext 方法和异步编程。作为开发人员,您有责任处理并发编程、限制、安全关闭等所有复杂问题。(应该注意的是,如果在 HttpListener 关闭时调用 EndGetContext,则往往会抛出异常,这是这是可能的,因为线程池负责执行异步调用的回调处理程序。)
The HttpListener class is indeed capable of hosting an endpoint like that inside of any kind of application (i.e. Windows Desktop app, Windows Service, Console app, etc.) Using HttpListener in a serial manner where a single request at a time can be processed is quite straightforward, however using it to provide any amount of concurrency can quickly get quite complex.
If you do wish to host a serial endpoint in a windows service, HttpListener is definitely the quickest approach. All it really takes is something like this:
A simple program like that will only process one request at a time, however the HttpListener can queue up quite a number of requests at a time. If you don't intend to handle high load with your service, it should be sufficient. If you need to handle high load and need concurrent request processing, you'll need to use the BeginGetContext/EndGetContext methods and asynchronous programming. The burden is on you the developer to deal with all the complexities of concurrent programming, throttling, safe and secure shutdown, etc. (It should be noted that calls to EndGetContext tend to throw if called while the HttpListener is being shut down, which is possible since the ThreadPool is responsible for executing the callback handler of asynchronous calls.)
HttpListener 已更新,并且将不再接受构造函数中的任何参数。为了设置前缀,您需要使用侦听器的 Prefixes 属性上的 .Add 函数和字符串数组。
HttpListener has been updated, and will no longer accept any arguments in the constructor. In order to set your prefixes, you'll need to use the .Add function on the listener's Prefixes property with an array of strings.