samedi 31 janvier 2015

First Time Web Services in ASP.NET VB


I am attempting to call a web service using JS from an asp.net website (VB) client side. I have used web services before but never set one up. I want to run async updates and queries. Any help would be great, similar examples, or better practices. Cant post images...


I believe I am having issues with Namespaces and proper calling of the methods from client events. Maybe something with the webconfig?


What I have done so far:

Make a new asp website in visual studio (website1). Add a new .asmx file named WebService.asmx. Uncomment System.Web.Script.Services.ScriptService(). Create a service reference using the wizard (ServiceReference1). On default.aspx add the script manager. Create button onclick and function. Then I run and I get this error on the js.


How I'm trying to call the service, I have done it like this in the past. One a system that was not mine. Does this method work?:



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


What the WebService.asmx looks like, I have no NameSpace for that 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 successfully imports and the webservice runs alone fine. Also my webconfig:



<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://ift.tt/1eW0XAj
-->

<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 fires and breaks on webservice line with this message:



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

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


Any advice?





Aucun commentaire:

Enregistrer un commentaire