How can I pass a variable from a ASP website to a desktop application?

假如想象 提交于 2020-01-23 19:47:08

问题


I am trying to pass a variable from an asp project (written in c#) to a desktop c# application. I know using Javascript you can use a JavaScriptSerializer, but is there an equivalent for asp?


回答1:


Depends on what you want to send back to the app or what is already being sent back by the server. i.e. let's say the result of a web page request were the "parameters" you speak of (you're not very clear, in the context of http and web communications). An ASP page can pass back the data to an app that requested data like this:

WebClient webClient = new WebClient();
var text = webClient.DownloadString("http://www.example.com/page.aspx");

... keep in mind, that's the code in the app. I assume that's what you're asking; because there's really only one way to data from an asp application.

If that's not what you're really asking, please be more detailed.




回答2:


but is there an equivalent for asp?

If you mean ASP.NET WebForms (it is worth being specific): your options include:

  • Use MVC4 and use an ApiController to create a restful API endpoint.
  • Use MVC and create a controller that returns HTML/XML/JSON depending on the accept header)
  • Add an IHTTPHandler mapped to a specific file extension to return the data. (This could use the accept header to return different formats).
  • Add an WCF endpoint.

I would tend to go for the first (allows me to learn ApiController with a simple example), but the second and third are both easy enough.

The final option gives you the greatest flexibility especially if SOAP/WS-* style is something you need) but the greatest learning curve.

For the first three the client is WebClient (or perhaps HttpWebRequest) with a known (or dynamically determined) URL. In the latter case WCF.

NB. A single web application (in IIS terms) can include a mixture of WebForms and MVC.



来源:https://stackoverflow.com/questions/11594259/how-can-i-pass-a-variable-from-a-asp-website-to-a-desktop-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!