Velocity Reviews

Velocity Reviews (
-   Software (
-   -   The type or namespace name 'localhost' could not be found (

Anthony Curtis 02-15-2011 02:23 PM

The type or namespace name 'localhost' could not be found
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 .


iranoobie 02-15-2011 10:26 PM


'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: //
WebService attribute:
http ://

Anthony Curtis 02-15-2011 11:37 PM

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>

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 :-
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 02-16-2011 12:06 AM

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

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.


private void button1_Click(object sender, System.EventArgs e) {
    Mod09Consume.tom.Math webservice = new Mod09Consume.tom.Math();
    decimal val1=System.Convert.ToDecimal(textBox1.Text);
    decimal val2=System.Convert.ToDecimal(textBox2.Text);


All times are GMT. The time now is 01:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.