|
-
Feb 15th, 2011, 01:54 PM
#1
Thread Starter
New Member
[RESOLVED] 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 ());
}
There are 3 other references to localhost in form1.cs, similar to the above.
The build error is reported twice for every line that references the localhost, 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 .
-
Feb 15th, 2011, 06:21 PM
#2
Re: The type or namespace name 'localhost' could not be found
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.
-
Feb 15th, 2011, 07:02 PM
#3
Thread Starter
New Member
Re: The type or namespace name 'localhost' could not be found
JMCILHinney - You are a star! 
Following your advice, I did the following....
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) {
Mod09Consume.tom.Math 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|