asp.net - Webservice方法500错误缺少参数
问题描述
我有一个网络服务,当我调用它时,我收到 500 错误。我关闭了友好消息,发现它缺少一个参数。在尝试调试时,我创建了一个默认为“Hello World”的新 asmx 页面
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")>
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<ToolboxItem(False)>
Public Class WebService1
Inherits System.Web.Services.WebService
<WebMethod()>
Public Function HelloWorld() As String
Return "Hello World"
End Function
<System.Web.Services.WebMethod()>
Public Function Test(ByVal x As String) As String
HttpContext.Current.Trace.Warn("entering test web method")
Return "hiya!"
'Provider.test(x)
End Function
End Class
我为此添加了一个新的 Test() Web 方法。如果它只是简单的,这个网络方法就可以工作
<System.Web.Services.WebMethod()>
Public Function Test() As String
HttpContext.Current.Trace.Warn("entering test web method")
Return "hiya!"
'Provider.test(x)
End Function
一旦我将 ByVal x 作为字符串输入,它每次都会抛出这个错误。我一定遗漏了一些东西,因为这是带有默认代码的默认 asmx 页面。
System.InvalidOperationException: Missing parameter: x.
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection
collection)
at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
我发现澄清这个问题的帖子都谈到了其他一些有问题的调用者(脚本、ajax、json 等),但我的是从网页直接调用
解决方案
推荐阅读
- ios - 带有redirectURI的Swift OAuth2.0
- bash - bash 中没有 sudo 的命令不起作用
- java - 如何在循环中更新标签
- ubuntu - 使用来自 Cloudflare 的 .pem 和 .key 设置 Ubuntu Apache2 SSL
- python - 使用字典和贪心算法解决 Set Cover 问题时的返回键
- java - 为什么 equals() 方法不能按预期工作?
- javascript - 如何在 2020 年使用纯 javascript 从 id 获取 YouTube 嵌入视频标题?
- php - 登录后回显受保护的内容
- ansible - 列表的 Ansible/YAML 格式不一致?
- sql-server - Vim dadbod 配置适配器