asmx Web服务方法名称无效

时间:2016-11-23 15:40:59

标签: vb.net web-services asmx

真的可以在这里使用一些帮助......

我试图在我的一个Web方法中使用一个对象作为参数,但是我收到以下错误消息:

System.InvalidOperationException: TestParameter Web Service method name is not valid.
   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

ASMX代码:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Web.Script.Serialization

' 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 TestService
    Inherits System.Web.Services.WebService

    <WebMethod()>
    Public Function TestParameter(ByVal req As TestObject) As String
        Return New JavaScriptSerializer().Serialize(req)
    End Function

    <WebMethod>
    Public Function TestGetParameter() As String
        Return New JavaScriptSerializer().Serialize(New TestObject)
    End Function

    Public Class TestObject
        Public var1 As String = String.Empty
        Public var2 As Integer = 1
    End Class

End Class

我已经花了好几个小时在谷歌上找工作,到目前为止找不到任何有用的东西:(

我已经在web.config中添加了以下内容

  <webServices>
    <protocols>
      <add name="HttpGet"/>
      <add name="HttpPost"/>
    </protocols>
  </webServices>

我的&#34;测试&#34; ajax电话:

   $(function () {
        debugger;
        request = { "var1": "", "var2": 1 };

        var settings = {
            async: true,
            crossDomain: true,
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            url: "http://server/TestService.asmx/TestParameter",
            method: "POST",
            data: "{ 'req':" + JSON.stringify(request) + "}"
        }

        $.ajax(settings).done(function (response) {
            console.log(response);
        });
    });

正如你所看到的,它很难简单,但它不起作用!我做错了什么?

使用Windows身份验证(无匿名)和ASP.NET v3.5在IIS7.5上运行;管道模式=经典

0 个答案:

没有答案