问题
I'm planning to have a desktop app interact with some .ASP or .ASPX pages on a server.
I've only done a little bit with .asp pages and I'm thinking I'd just Post or Get a URL with some variables:
MySite.com/Functions.asp?FunctionName=?Paramater1=somevalue?Parameter2=...
I'm wondering if there is any better way to go about this?
Am I missing something? Is there perhaps a better way to go about this?
回答1:
Windows Communication Foundation or Web Services may be a better idea if you don't require the overhead of the web page that ASP or ASPX requires. Those would be my suggestions for a better way to go about doing some of this. This is assuming you don't have the pages built already and are at the early stages of designing this.
WCF is better if you just want to have services communicated back and forth, which can takes out some of what HTTP sets up and handles but could be better if you want to minimize the data passed around I'd think. WCF is part of the .Net 3.0 framework, so it may not be something to be installed necessarily as it may already be there by default in some cases. For example, this is what replaced .Net Remoting which would have been an older way to pass objects between machines in other ways using non-standard ports and may be a bit more work in terms of infrastructure. Web services are better if you don't need all that there is to a web page and are OK with having messages go back and forth in SOAP or POX or some other format that doesn't have to be HTML. Instead of an ASPX you'd have an ASMX and some code behind but in theory having a well-built set of services should help if you ever have to add on a web front-end or tie into someone else's systems.
回答2:
The suggestions with WCF and REST are all good suggestions, but if you just want something easier you might just want to try System.Net.WebClient.
.NET C# Example:
For instance the DownloadString method which returns a string from the specified URL.
string status = WebClient.DownloadString("http://yourdomain.com/check-app-status.asp(x)");
if (status == "blabla")
{
}
VB6 Form application sample:
Private Sub Form_Load()
Dim http
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET", "http://example.com/", False
http.send ""
ResponseTextBox.Text = http.responseText
End Sub
The above VB6 example assumes that you have a textbox called ResponseTextBox on your form
In your ASP(.NET) pages you can do something like:
Response.ContentType = "text/plain";
Response.Write(AppStatus);
For more information see: http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx
回答3:
Look into architecting your server side to be RESTful. In shot that means that you expose "resources" and apply a well known interface (CRUD) for them. You can read more about it in details here: http://www.xfront.com/REST-Web-Services.html
p.s. a very funny explanation here: http://tomayko.com/writings/rest-to-my-wife
来源:https://stackoverflow.com/questions/2915129/suggestions-pointers-for-post-get-to-an-asp-or-aspx-page-from-a-desktop-app