ASP.NET VB 首次使用 Web 服务

First Time Web Services in ASP.NET VB

我正在尝试从 asp.net 网站 (VB) 客户端使用 JS 调用 Web 服务。我以前使用过 Web 服务,但从未设置过。我想 运行 异步更新和查询。任何帮助都会很好,类似的例子或更好的做法。无法 post 图片...

我认为我在命名空间和从客户端事件正确调用方法方面遇到了问题。也许与 webconfig 有关?

到目前为止我做了什么:
在 visual studio (website1) 中创建一个新的 asp 网站。添加一个名为 WebService.asmx 的新 .asmx 文件。 取消注释 System.Web.Script.Services.ScriptService()。使用向导创建服务引用 (ServiceReference1)。在 default.aspx 添加脚本管理器。创建按钮 onclick 和功能。然后我 运行 并且我在 js 上得到了这个错误。

我是如何尝试调用该服务的,我过去就是这样做的。一个不是我的系统。这个方法有用吗?:

    function test() {
        ServiceReference1.WebService.HelloWorld();            
    }
<input type="button" onclick="test()"/>

WebService.asmx 是什么样子,我没有用于该测试的命名空间。应该有吗?:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class

app_reference 成功导入,网络服务 运行 单独正常。还有我的网络配置:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="WebServiceSoap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:55800/WebService.asmx" binding="basicHttpBinding"
                bindingConfiguration="WebServiceSoap" contract="ServiceReference1.WebServiceSoap"
                name="WebServiceSoap" />
        </client>
    </system.serviceModel>
</configuration>

JS 在 Web 服务行上触发并中断并显示以下消息:

Unhandled exception at line 13, column 13 in http://localhost:55800/Default.aspx

0x800a1391 - JavaScript runtime error: 'ServiceReference1' is undefined

有什么建议吗?

只需调用 {WebServiceClass.Method}.

WebService.HelloWorld()