How to invoke webservice from aspx page?

Discussion in 'ASP .Net Web Services' started by Lupakkiotto, Feb 9, 2006.

  1. Lupakkiotto

    Lupakkiotto Guest

    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
    Lupakkiotto, Feb 9, 2006
    #1
    1. Advertising

  2. 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.

    > 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
    Robert Wilczynski, Feb 9, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel
    Replies:
    0
    Views:
    562
    Samuel
    Jul 30, 2003
  2. kapila Wijethilaka

    How to Invoke IExplorer from aspx page

    kapila Wijethilaka, Nov 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    498
    Tommy
    Nov 28, 2003
  3. Standist
    Replies:
    0
    Views:
    1,377
    Standist
    Feb 8, 2006
  4. С»ÒÀÇ

    Why invoke a webservice failed in asp.net ?

    С»ÒÀÇ, Dec 13, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    605
    Mark Fitzpatrick
    Dec 13, 2007
  5. kapila Wijethilaka

    How to Invoke IExplorer from aspx page

    kapila Wijethilaka, Nov 28, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    122
    kapila Wijethilaka
    Nov 28, 2003
Loading...

Share This Page