[英]call asp.net webmethod in windows project
如何從Windows應用程序在ASP.NET中調用此WebMethod
?
我嘗試使用Web請求發布方法,但是它返回ASP.NET頁的XML。
這是我的網絡方法:
[WebMethod()]
public static string Senddata(string value)
{
return "datareceived" + value;
}
嘗試這個:
var theWebRequest = HttpWebRequest.Create("http://YOURURL/YOURPAGE.aspx/Senddata");
theWebRequest.Method = "POST";
theWebRequest.ContentType = "application/json; charset=utf-8";
theWebRequest.Headers.Add(HttpRequestHeader.Pragma, "no-cache");
using (var writer = theWebRequest.GetRequestStream())
{
string send = null;
send = "{\"value\":\"test\"}";
var data = Encoding.ASCII.GetBytes(send);
writer.Write(data, 0, data.Length);
}
var theWebResponse = (HttpWebResponse)theWebRequest.GetResponse();
var theResponseStream = new StreamReader(theWebResponse.GetResponseStream());
string result = theResponseStream.ReadToEnd();
// Do something with the result
TextBox1.Text = result;
注意:您需要用實際值替換YOURURL
和YOURPAGE
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.