首页 > 解决方案 > 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 等),但我的是从网页直接调用

测试方法网页视图

标签: asp.netweb-services

解决方案


推荐阅读