好吧,我似乎找不到合适的 Windows Azure 示例。我有一个简单的 hello world 应用程序,基于 this tutorial 。我想要自定义输出而不是 JSON 或 XML。所以我创建了如下界面:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(UriTemplate = "session/create", Method = "POST")]
string createSession();
}
public class MyService : IService
{
public string createSession()
{
// get access to POST data here: user, pass
string sessionid = Session.Create(user, pass);
return "sessionid=" + sessionid;
}
}
在我的一生中,我似乎无法弄清楚如何访问 POST
数据。请帮忙。谢谢!
最佳答案
如果您有 HttpContext,则可能有一个包含表单数据的 Request 对象。我的部分内容是基于 ASP.Net 标签来解决这个问题的,所以如果这是不正确的,那么可能需要以另一种方式处理这个问题,但在我看来,它看起来很像一个 Web 服务。
<小时/>编辑:HttpRequest是具有 Form 属性的类,如果这是 HTTP 请求,则该类应该是存储 POST 数据的位置。这是 System.Web 的一部分,因此我记得它应该很容易使用。
<小时/>Sample code显示 Request.Form 属性:
int loop1;
NameValueCollection coll;
//Load Form variables into NameValueCollection variable.
coll=Request.Form;
// Get names of all forms into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Form: " + arr1[loop1] + "<br>");
}
这假设周围有一个 HttpRequest 实例。
<小时/>WCF Simplified Part 4: Comparing the Request/Reply and One-Way Patterns传入一个参数,以便您的“createSession”方法必须接受它会出现的那些字符串。我习惯了 ASP.Net 世界,其中有一些内置对象,如请求、响应、服务器、应用程序和 session 。
<小时/>是的,如果您确实尝试更改方法签名,因为在我链接的最后一个示例中存在传递参数的方法,但我不知道这是否适合您的情况。
关于asp.net - Windows Azure 访问 POST 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4543669/