The type or namespace name 'localhost' could not be found

Discussion in 'Software' started by Anthony Curtis, Feb 15, 2011.

  1. Anthony Curtis

    Anthony Curtis

    Joined:
    Feb 15, 2011
    Messages:
    3
    Location:
    London
    ok here goes. I am new to forums and new to this forum especially so bear with me.

    I am trying to work through a tutorial on Visual Studio Professional 2010 on USING an XML Web Service from within C#.

    The tutorial provides a Math Web Service and a solution project called Consume (which is a visual c# project using the windows application template).

    The tutorial assumes that the IIS server and the client are on the same box. However, unfortuately for me my client is running Windows XP Home Edition which does not support IIS. So, I have had to install IIS on a Windows Vista laptop and installed the Math Web Service on it successfully.

    My problem is that when I attempt to build the Consume solution, within Visual Studio on my home edition laptop it comes back with the error below:-

    The type or namespace name 'localhost' could not be found (are you missing a using directive or an assembly reference?)

    This error is reported whereever the localhost is referenced in my Form1.cs. For instance the code snippet below:-

    private void button1_Click(object sender, System.EventArgs e) {
    localhost.Math webservice = new localhost.Math();
    decimal val1=System.Convert.ToDecimal(textBox1.Text);
    decimal val2=System.Convert.ToDecimal(textBox2.Text);
    MessageBox.Show(webservice.Add(val1,val2).ToString());
    }
    The build error is reported twice for every line that references the localhost. There are 4 references to localhost in form1.cs, so the build gives me the error a total of 8 times.

    Can anybody tell me how I amend the code so that instead of using the localhost it uses the vista laptop that is running IIS and has the Math Web Service installed?

    localhost is also referred to in properties of the Web References in solution explorer too - does this need to be changed also, if so how?

    Please note that I am not an expert in any of this I am just learning, so please keep this in mind when responding.

    If you think it would help, I could zip the consume solution and math web service code and attach it to the thread, if needed.

    Thanks in advance .

    Anthony
     
    Anthony Curtis, Feb 15, 2011
    #1
    1. Advertising

  2. Anthony Curtis

    iranoobie

    Joined:
    Feb 15, 2011
    Messages:
    1
    Hi.

    'localhost' in this case refers to the server name that contains the web service Math. The web reference in solution explorer is most likely pointing to a specified URL, or the URL localhost; both of which in this case would not work

    Another issue to consider here is that you cannot call web services directly via a remote server. This is to prevent XSS injections. I'm pretty sure the only exception to this rule are web services that are exposed via the WebService attribute. You could use Middleware (SOAP) or a client-proxy to talk to the service remotely.

    and since I can't post links....
    Consuming and referencing a web service in VS 2010:
    http: //blogs.msdn.com/b/devschool/archive/2010/01/01/consuming-a-hosted-web-service-using-visual-studio-specifically-vwd-2010.aspx
    WebService attribute:
    http ://msdn.microsoft.com/en-us/library/bb398998.aspx
     
    Last edited: Feb 15, 2011
    iranoobie, Feb 15, 2011
    #2
    1. Advertising

  3. Anthony Curtis

    Anthony Curtis

    Joined:
    Feb 15, 2011
    Messages:
    3
    Location:
    London
    Hi iranoobie,

    The server running IIS is called dumbo-pc

    and if I put the url... http colon slash slash followed by <IIS servername>/MathWebService/math.asmx

    NB. this site wont let me put the url in as a link so it is broken up as above

    into the address of my firefox browser (on a windows xp home edition laptop client) it connects fine and shows me all the operations that are supported.

    Likewise, the Web reference URL property of my Web references subfolder is the same...
    http colon slash slash
    followed by <IIS servername>
    /MathWebService/math.asmx

    The folder name property is 'dumbo'

    and the line that errors is:-

    dumbo.Math webservice = new dumbo.Math();
    as does
    dumbo-pc.Math webservice = new dumbo-pc.Math();

    The web service Math is installed and I can see it in windows explorer at :-
    \\Dumbo-pc\C\inetpub\wwwroot\MathWebService
    on my Vista laptop(which is running IIS)

    My windows XP home edition laptop and my Vista laptop running IIS are talking via my BT homehub as members of a workgroup.

    I read the link you sent and it tells me to do pretty much what I have done already.

    I dont quite understand the implications of your second paragraph or how to act upon what you mention therein. I am very new to all this and am struggling to understand the root of the problem. I thought/hoped it would be a simple syntax issue around how I reference the .Math ie. replace the word localhost with text that points to the web server running the math service on my vista laptop. I think you are implying that there is more to it than that and / or what I am trying to do wont work unless I do xyx steps before after and during the creation of the consume solution.

    Any more leads would be appreciated.
     
    Anthony Curtis, Feb 15, 2011
    #3
  4. Anthony Curtis

    Anthony Curtis

    Joined:
    Feb 15, 2011
    Messages:
    3
    Location:
    London
    Problem solved - hooray

    I was advised by a colleague that 'If you've referenced the web service then you must have a Math class in your project. What namespace is that class a member of? That's what you need to put there. If by no other means, you should be able to use the Object Browser to find it.'

    So....
    In Visual Studio, I opened my consume solution then
    I opened the object browser using Ctrl+Alt+J and browsed to 'My solution', which showed that the namespace was called Mod09Consume.tom.
    I replaced all instances of the text <localhost> with the text <Mod09Consume.tom.>, did a rebuild and it compiled and run perfectly.

    For completeness sake and thereby help other dimwits like myself here is the corrected piece of code in bold.

    Code:
    private void button1_Click(object sender, System.EventArgs e) {
         [B]Mod09Consume.tom.Math[/B] webservice = new Mod09Consume.tom.Math();
         decimal val1=System.Convert.ToDecimal(textBox1.Text);
         decimal val2=System.Convert.ToDecimal(textBox2.Text);
         MessageBox.Show(webservice.Add(val1,val2).ToString());
    }
    Thanks
     
    Anthony Curtis, Feb 16, 2011
    #4
    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. Lisa Hetherington
    Replies:
    8
    Views:
    4,179
    John Thompson
    Apr 21, 2005
  2. Kendal Emery

    OT:: Namespace Miner

    Kendal Emery, Feb 12, 2004, in forum: MCSE
    Replies:
    11
    Views:
    2,020
    Rowdy Yates
    Feb 13, 2004
  3. Dutch Treat
    Replies:
    4
    Views:
    4,934
    Boomer
    Jun 21, 2004
  4. sgauthier
    Replies:
    3
    Views:
    2,537
  5. abnerliu
    Replies:
    0
    Views:
    1,179
    abnerliu
    Aug 4, 2011
Loading...

Share This Page