Results 1 to 6 of 6

Thread: is a 'namespace' but is used as a 'type'

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    is a 'namespace' but is used as a 'type'

    I'm playing at trying to get a web service to work following a tutorial.

    So I have a solution with two projects - one a web service the other a windows app.

    The web service 'runs' okay. This is the code for the web service:

    Code:
    using System;
    using System.Data;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.ComponentModel;
    
    namespace WebService1
    {
        /// <summary>
        /// Summary description for Service1
        /// </summary>
        [WebService(Namespace = "http://localhost/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(false)]
        public class Service1 : System.Web.Services.WebService
        {
    
            [WebMethod]
    
            public DateTime GetServerTime()
            {
    
                return DateTime.Now;
    
            }
        }
    }
    I'm trying now to call the web service from the windows app. I have a form with a text box and button on it. I have also added a web reference - this opened a window where I could 'select web services in this solution' - it found 'Service1' (which is the class name above) and named the reference 'fred'. This is the code for the form.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using WebDemoClient.fred;
    
    
    namespace WebDemoClient
    {
        public partial class WebDemoClient : Form
        {
            public WebDemoClient()
            {
                InitializeComponent();
            }
    
            private void cmdServerTime_Click(object sender, EventArgs e)
            {
                fred oService = new fred();
    
                this.txtServerTime.Text = oService.GetServerTime().ToString();
    
                this.txtServerTime.Text = fred.GetServerTime().ToString();
    
            }
        }
    }
    When I typed the line in red above - after I had typed WebDemoClient (which is the namespace of the windows app project) when I typed the full stop intellisense displayed the choices of
    {}fred
    {}properties

    ... so I guess it knows what fred is.

    However when I try to build it, it falls over on the line in blue. It says

    WebDemoClient.fred is a 'namespace' but is used like a 'type'

    What am I doing wrong. It seems the form can 'see' the web service but I am not referencing it properly.

    Thanks for any help.

  2. #2
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: is a 'namespace' but is used as a 'type'

    does the name space 'WebDemoClient.fred' actually contain a Class called fred....

    so, without namespace declaration...



    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    
    namespace WebDemoClient
    {
        public partial class WebDemoClient : Form
        {
            public WebDemoClient()
            {
                InitializeComponent();
            }
    
            private void cmdServerTime_Click(object sender, EventArgs e)
            {
                WebDemoClient.fred.fred oService = new WebDemoClient.fred.fred();
    
                this.txtServerTime.Text = oService.GetServerTime().ToString();
    
                this.txtServerTime.Text = WebDemoClient.fred.fred.GetServerTime().ToString();
    
            }
        }
    }
    hope this helps...or even makes sense..

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: is a 'namespace' but is used as a 'type'

    Thanks for your reply.

    There is no class named Fred in the web service. The class is called Service1.

    If in the declarations I type ...

    using WebDemoClient. - as soon as I type the dot intellisense displays a box that provides the choices ...

    {}fred
    {}properties

    So I guess it can 'see' the web service.

    However, if in the function I start to type ...

    WebDemoClient. intellisense does not show anything

    So, although it found 'fred' when typing the declaration, it doesn't find it when trying to reference it in a function.

    Thanks for your help.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: is a 'namespace' but is used as a 'type'

    What happens when you type WebDemoClient.fred and continue with a dot? Do this in the servertime_click method.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: is a 'namespace' but is used as a 'type'

    Quote Originally Posted by mendhak
    What happens when you type WebDemoClient.fred and continue with a dot? Do this in the servertime_click method.
    Nothing - there is nothing there.

    Could you explain 'Do this in the servertime_click method' please. No idea what you mean.

    Cheers.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: is a 'namespace' but is used as a 'type'

    In here:

    private void cmdServerTime_Click(object sender, EventArgs e)
    {

    Is where I meant that you should attempt to investigate what is available in intellisense.

    Now, you say there's nothing, so I think we should have a look at your proxy class. You can go to your web references and double click on it (I think, might be right click-view code) and you will see the proxy class generated for your web reference. Have a look at it. Look at the accessor levels, are they private or public?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width