我正在尝试创建一个可以执行 HTTP GET 请求的 ASMX Web 服务。我有以下简单的代码片段来说明我已经完成的工作。
using System.Web.Script.Services;
...
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string HelloWorld(HttpContext context)
{
return context.Request.Params.Get("userId").ToString();
}
除此之外,我还在我的 Web.config 文件中添加了以下节点
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
我面临的问题是,System.Web.HttpContext cannot be serialized because it does not have a parameterless constructor
每当我尝试调试此 Web 服务时,我都会不断收到可怕的“”错误消息。我不知道问题出在哪里,我非常感谢为使我摆脱这种困境而提供的任何帮助。我意识到 HTTP GET 请求应该非常简单,但我真的不确定我的挫败感是什么。