【问题标题】:Getting POST data from form with WCF Service Application使用 WCF 服务应用程序从表单获取 POST 数据
【发布时间】: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 的一部分,而不是查询字符串

标签: c# html wcf


【解决方案1】:

我发现了这个other_wcf_stuff。所有技巧都在 web.config 中(必须声明绑定(仅 webHttpBinding)和行为配置)。我现在的服务界面也是:

[服务合同] 公共接口 IService { [运营合同] 字符串 GetData(流 aoInput); }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多