how to use Manespace Property in code behind

Discussion in 'ASP .Net Web Services' started by Rocio, May 25, 2004.

  1. Rocio

    Rocio Guest

    I have a Default.asmx file that contains only this line:

    <%@ WebService Language="vb" Codebehind="WebService.vb"
    class="MyProgramBS.WebService" %>

    All my WEbMethods are in MyProgramBS.WebService: e.g.
    <WebMethod()> Public Function CanPayOnline(ByVal loginID As Long) as
    Boolean()

    When I test this, the default value of the namspace is
    http://tempuri.org/

    I tried modifying the code in Default.asmx as:
    Imports System.Web.Services

    <System.Web.Services.WebService(Namespace:="http://www.MyWebSite.net/WebService")>
    _
    Public Class WebService
    Inherits System.Web.Services.WebService

    ' WEB SERVICE EXAMPLE
    ' The HelloWorld() example service returns the string Hello World.
    ' To build, uncomment the following lines then save and build the
    project.
    ' To test this web service, ensure that the .asmx file is the
    start page
    ' and press F5.
    '
    '<WebMethod()> _
    'Public Function HelloWorld() As String
    ' Return "Hello World"
    'End Function

    End Class

    but nothing happens. I think it is because I do not write any of my
    web methods in the asmx file, but I redirect to WebService.vb . So how
    can I change the Namespace this way?
     
    Rocio, May 25, 2004
    #1
    1. Advertising

  2. Rocio

    Jan Tielens Guest

    The TempUri namespace is the namespace for the XML soap message! You can
    control this by using the WebService attribute, for example:

    [WebService(Namespace="http://microsoft.com/webservices/")]
    public class MyWebService {
    // implementation
    }

    --
    Greetz
    Jan
    ________________
    Read my weblog: http://weblogs.asp.net/jan


    "Rocio" <> schreef in bericht
    news:...
    > I have a Default.asmx file that contains only this line:
    >
    > <%@ WebService Language="vb" Codebehind="WebService.vb"
    > class="MyProgramBS.WebService" %>
    >
    > All my WEbMethods are in MyProgramBS.WebService: e.g.
    > <WebMethod()> Public Function CanPayOnline(ByVal loginID As Long) as
    > Boolean()
    >
    > When I test this, the default value of the namspace is
    > http://tempuri.org/
    >
    > I tried modifying the code in Default.asmx as:
    > Imports System.Web.Services
    >
    >

    <System.Web.Services.WebService(Namespace:="http://www.MyWebSite.net/WebServ
    ice")>
    > _
    > Public Class WebService
    > Inherits System.Web.Services.WebService
    >
    > ' WEB SERVICE EXAMPLE
    > ' The HelloWorld() example service returns the string Hello World.
    > ' To build, uncomment the following lines then save and build the
    > project.
    > ' To test this web service, ensure that the .asmx file is the
    > start page
    > ' and press F5.
    > '
    > '<WebMethod()> _
    > 'Public Function HelloWorld() As String
    > ' Return "Hello World"
    > 'End Function
    >
    > End Class
    >
    > but nothing happens. I think it is because I do not write any of my
    > web methods in the asmx file, but I redirect to WebService.vb . So how
    > can I change the Namespace this way?
     
    Jan Tielens, May 25, 2004
    #2
    1. Advertising

  3. Tx. for the reply.
    Yes, I know I have to do this, but where? In my Default.asmx.vb file?
    Well I put it there, but I do not implement any WebMethod here, but in
    another file. What I do in Default.aspx is to redirect the program to
    this other file where I implement my WebMethods.

    This is what I have:

    MySolution (2 projects)
    Project
    Default.asmx
    web.config
    Global.asax
    ProjectBS
    WebService.vb

    Default.asmx is empty, but contains a line that redirects it to
    ProjectBS.WebService.vb
    However, in Default.asmx.vb I put the Namespace as you indicated and as
    I did before, and nothing happens.....

    Is it because I have the WebMethods in another file?



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Rocio Katsanis, May 25, 2004
    #3
  4. Rocio

    Jan Tielens Guest

    When you open the CODE of the ASMX page (physically the vb file), you'll see
    the code for your web services. Since you are using VB.NET look for Public
    Class .... Remember that you must apply this attribute or class level (not
    method level) and that attributes in VB.NET are between < and >.

    --
    Greetz
    Jan
    ________________
    Read my weblog: http://weblogs.asp.net/jan


    "Rocio Katsanis" <> schreef in bericht
    news:%...
    >
    > Tx. for the reply.
    > Yes, I know I have to do this, but where? In my Default.asmx.vb file?
    > Well I put it there, but I do not implement any WebMethod here, but in
    > another file. What I do in Default.aspx is to redirect the program to
    > this other file where I implement my WebMethods.
    >
    > This is what I have:
    >
    > MySolution (2 projects)
    > Project
    > Default.asmx
    > web.config
    > Global.asax
    > ProjectBS
    > WebService.vb
    >
    > Default.asmx is empty, but contains a line that redirects it to
    > ProjectBS.WebService.vb
    > However, in Default.asmx.vb I put the Namespace as you indicated and as
    > I did before, and nothing happens.....
    >
    > Is it because I have the WebMethods in another file?
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Jan Tielens, May 26, 2004
    #4
  5. OK.

    I got it. Since I have implemented the class WebService in another file
    (not in my asmx.vb) and this file resides in another project (a class
    project), I added the attribute <WebService> to the class in this file:

    <System.Web.Services.WebService(Namespace:="http://www.mywebsite.com/Web
    Service")> _
    Public Class WebService
    Inherits System.Web.Services.WebService

    End Class

    Previously I had a simple Public Class WebService .... in this file, and
    the Namespace attribute was in the asmx.vb file.

    Tx!



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Rocio Katsanis, May 26, 2004
    #5
  6. Rocio

    Jan Tielens Guest

    Np! Glad I could help!

    --
    Greetz
    Jan
    ________________
    Read my weblog: http://weblogs.asp.net/jan


    "Rocio Katsanis" <> schreef in bericht
    news:%...
    > OK.
    >
    > I got it. Since I have implemented the class WebService in another file
    > (not in my asmx.vb) and this file resides in another project (a class
    > project), I added the attribute <WebService> to the class in this file:
    >
    > <System.Web.Services.WebService(Namespace:="http://www.mywebsite.com/Web
    > Service")> _
    > Public Class WebService
    > Inherits System.Web.Services.WebService
    >
    > End Class
    >
    > Previously I had a simple Public Class WebService .... in this file, and
    > the Namespace attribute was in the asmx.vb file.
    >
    > Tx!
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Jan Tielens, May 26, 2004
    #6
    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. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    653
    Alphonse Giambrone
    Jun 28, 2003
  2. Umut Tezduyar
    Replies:
    3
    Views:
    2,299
    Scott Allen
    Nov 13, 2004
  3. Daniel Manes

    Code-Behind Pain in the Behind!

    Daniel Manes, Jun 10, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    711
  4. pedestrian via DotNetMonster.com

    ASP.NET 2.0: To use or not to use code behind?

    pedestrian via DotNetMonster.com, Sep 27, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    363
    Steven Nagy
    Sep 28, 2006
  5. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    536
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
Loading...

Share This Page