Attempting to call a web service using JS from an ASP.NET website (VB) client side. Although familiar with web services, setting one up is new territory for me. Looking to implement async updates and queries. Any assistance, examples, or best practices would be greatly appreciated. Unfortunately, unable to post images...
Seem to be encountering issues related to Namespaces and the correct way of calling methods from client events. Could it possibly be something in the webconfig?
Progress so far:
Started by creating a new ASP website in Visual Studio (website1). Added a new .asmx file named WebService.asmx. Uncommented System.Web.Script.Services.ScriptService(). Created a service reference using the wizard (ServiceReference1). On default.aspx, added the script manager. Created a button onclick and function. Upon running, encountered an error in the JavaScript.
The method I'm trying to use to call the service resembles what I've done in the past on a different system. Will this approach work?:
function test() {
ServiceReference1.WebService.HelloWorld();
}
<input type="button" onclick="test()"/>
Noticed that in the WebService.asmx there is no Namespace specified for that particular test. Should there be one?:
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
The app_reference imports successfully and the webservice runs fine on its own. Additionally, here is my webconfig:
<?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>
When the JS fires, it breaks on the webservice line displaying this message:
Error at line 13, column 13 in http://localhost:55800/Default.aspx
JavaScript runtime error: 'ServiceReference1' is undefined
Any suggestions or advice would be greatly appreciated.