【发布时间】:2012-03-28 05:12:18
【问题描述】:
我厌倦了使用 WCF 获取 POST 数据(我是新手),所以我真的不知道我做错了什么。我正在尝试使用此表单发送 POST 数据:
<!doctype html>
<html>
<head></head>
<body>
<form action='http://localhost:56076/Service.svc/invoke' method="post" target="_blank">
<label for="firstName">First Name</label>: <input type="text" name="firstName" value="" />
<label for="lastName">Last Name</label>: <input type="text" name="lastName" value="" />
<input type="submit" />
</form>
</body>
</html>
我正在使用 WCF 服务应用程序(在 VS2008 中):
//IService.cs: [服务合同] 公共接口 IService { [运营合同] [WebInvoke(方法 = "POST", UriTemplate = "invoke", BodyStyle = WebMessageBodyStyle.WrappedRequest)] 字符串 GetData(流 aoInput); } //Service.svc.cs 公共类服务:IService { 公共字符串 GetData(流 aoInput) { 使用 (StreamReader loReader = new StreamReader(aoInput)) { 字符串主体 = loReader.ReadToEnd(); var @params = HttpUtility.ParseQueryString(body); 返回@params[“名字”]; } } }当我在表单上按提交后执行服务时,我的代码中的断点没有响应。我做错了什么?
【问题讨论】:
-
当您执行 POST 操作时,如果我没有记错,则不会评估任何查询字符串。因此没有回复回来。 POST 期间的参数是 RequestBody 的一部分,而不是查询字符串