Namespaces and web references

  • Thread starter Thread starter Rob Richardson
  • Start date Start date
R

Rob Richardson

Greetings!

I am trying to understand strange behavior in a little test application I
put together to talk to a Web service. If I create an application and add a
Web reference to my web service, Intellisense knows about my web service and
my application builds and runs correctly. The code using the Web service
is:

namespace WebServiceTest
{
<snip>
private void button1_Click(object sender, System.EventArgs e)
{
localhost.CommandRelayer theRelayer;
}
}

But if I change the namespace to PrimeProData.Labels.WebServiceTest, the
name "localhost" is no longer recognized. I do not have a default namespace
set for this project. What do I have to do to make sure I can see a web
reference if I change the namespace of a project?

Thanks very much!

Rob
 
Hi Rob,

When you first generated the Web Reference, the proxy that was created
contained code that was in the same namespace as your project. So, your
original web reference proxy is in the WebServiceTest.localhost namespace.
This is why it was easy for you to reference the Web Service with only
localhost.CommandRelayer.

When you changed your namespace to PrimeProData.Labels.WebServiceTest, then
the Web Service proxy was no longer in the same namespace as your code and
localhost.CommandRelayer doesn't work. Additionally, doing an update on the
Web Reference didn't work because your project properties probably still had
the default namespace of WebServiceTest.

One way to fix this is to right click on the project and select Properties.
In the Project Property Pages dialog, select Common Properties, General.
Then change the Default Namespace property to
PrimeProData.Labels.WebServiceTest. Select OK to close the dialog. Next,
open the Web References folder, right-click on localhost, and select Update
Web Reference. After this, your code should compile and run fine.

Joe
 
Back
Top