How to invoke webservice from aspx page?

L

Lupakkiotto

Hi! I am a newbye about asp.net and I would like to know where I am wrong
doing this thing...
I have a webservice HelloWorldService.asmx with this code:

<%@ WebService Language="VB" Class="Samples.AspNet.HelloWorldService" %>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Namespace Samples.AspNet
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class HelloWorldService
Inherits System.Web.Services.WebService
Public pippo As String
<WebMethod()> _
Public Sub HelloWorld(ByVal query As String)
pippo = query
End Sub
<WebMethod()> _
Public Function Hello() As String
Return pippo
End Function
End Class
End Namespace

---
Then I have a simple Default3.aspx web page with a button and a textbox.
This is the code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim xxx As New localhost.HelloWorldService


xxx.HelloWorld("pippone")


TextBox1.Text = xxx.Hello


End Sub

When I click the button I think that webservice is called and then it
returns the string "pippone" in textbox1.. but nothing...
Where I am wrong??
Thanks in advance,
Marco
 
R

Robert Wilczynski

Hi,

Web services are stateless meaning that when you call the Hello() function
the value assigned to pippo field no longer exists. A new instance of the
web service is created each time you call a method on the proxy. You should
remove the HelloWorld() method and return the string from the modified Hello()
method and not store it in a field:

<WebMethod()> _
Public Function Hello(ByVal query As String) As String
Return query
End Function

Best regards,
Robert Wilczynski.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top