Changing the namespace for a Web Reference in a Project to be Made Into a VS Project Template
Asked Answered
T

1

8

When I add a web reference to a project, it comes up with a default namespace of: com.wpdevs.myservice. This is the namespace I'd have expected it to use in the application.

When I add the using statement to the project, I have to add:

using MyProject.com.wpdevs.myservice;

I'd like to find a way to eliminate having to reference the project name in the using statement. The project I'm putting together now is destined to be converted into a VS Project template and having that rather strange reference in there, or even having a per-project reference, isn't something I'd like to have in the project.

Torquay answered 14/3, 2010 at 6:9 Comment(0)
L
6

When adding a web reference, you get to choose the namespace, but it will be relative to the default namespace of the project. I don't know of any way to change that.

OTOH, you could try using the WSDL.EXE program to generate your proxy classes. This accepts a /namespace switch that allows you to set the full namespace for the proxy classes.

I would have to know what you were doing with your project template to know how to help you with that.


I'm making a guess based on what you say about your project template. In creating the template, you started with a project named "MyProject". When you added a web reference into that project, the namespace used was "MyProject.something". You'd like the namespace used in projects created from this template to be "something".

Although it's not normally a good idea to edit generated code, in this case, you can get away with it. Edit your Reference.cs and manually change the namespace to "something". You'll then include that file into the project template. Projects created using this template will have a web reference in the "something" namespace.

Lydie answered 14/3, 2010 at 6:18 Comment(2)
The template is essentially a blank starting project with a good chunk of re-usable code/functions prebuilt. My team builds a lot of small one-off web-based tools for use internally within the company. The old project "template" was a copy & paste job that caused tons of headache over the years. The web references are for a few commonly used services that the template, and later the full-on projects will use.Torquay
Editing the generated files is precisely what I did after I read your first suggestion. Figured if you can change the namespace with a parameter, it must be editable too. Works like a charm. Thanks!Torquay

© 2022 - 2024 — McMap. All rights reserved.