I've added a service reference to my mvc4 web project and left it with the default namespace "ServiceReference1", but when I wanna use that namespace, visual studio can't find it, like it doesn't exist, the webservice is up and working fine. What exactly am I doing wrong?
4 Answers
I found the solution HERE which as Hoakie mentioned below instructions worked for me and my reference.cs is generated properly now:
1) Right click on Service Reference
2) Select Configure Service Reference
3) Uncheck "Reuse types in referenced assemblies"
and Voila!

- 37,241
- 25
- 195
- 267

- 4,533
- 9
- 40
- 85
-
4It worked for me as well. But does anybody no, what is its significance and why it worked? – Manoj Attal Jan 23 '15 at 06:53
-
Huh... lost half a working day on this, searched the entire file hierarchy for the problem and this resolved it! Thank you very much friend! – Leonidas Aug 03 '15 at 15:06
-
Awesome... As it is not working as expected why did the respective developers marked it by default?!!! They just made so to get many developers waste their half a day :( – Chakri Oct 27 '15 at 15:16
-
worked for me in VS 2015.Would love to know the reasoning of this solution – sohaiby Oct 02 '17 at 09:28
-
Thank you. It worked for me as well, but the same as the others, I am not really sure about the reason why it worked. – Marius Popa Jan 31 '19 at 10:04
-
Thank you! so much time wasted! – BunkerBilly Jun 26 '19 at 10:44
-
Just to add to that I found a reboot of my VS was required – Richard Housham Sep 21 '22 at 12:21
This is caused by having the same namespace
name as class name.
Change your namespace to a name that is not the same name as your class and this will compile

- 4,683
- 17
- 58
- 96
-
The class name is "BaseJob" with namespace "SmsPanel, the service reference namespace is "ServiceReference1"... – arash moeen Apr 09 '14 at 13:12
-
1I can't find any service model binding in my web.config file, though I'm not sure the structure in mvc 4 but shouldn't the endpoint be added to my webconfig file ??? – arash moeen Apr 09 '14 at 13:18
-
if you have added the reference via visual studio it will add necessary things in web.config by it self – Reza Apr 09 '14 at 14:02
-
well it didn't add anything in my webconfig and that's the problem. – arash moeen Apr 09 '14 at 14:06
Look at the proxy class that is generated by visual studio for your service and see what is the namespace and the class name

- 18,865
- 13
- 88
- 163
-
1
-
1There is a ServiceReference folder in your solution and generated files are there – Reza Apr 09 '14 at 13:31
-
If you're talking about the service reference folder in my solution then there's nothing there than my service references. – arash moeen Apr 09 '14 at 13:38
-
-
It's a web service and I've been using it in my other projects, php and asp.net project which works perfectly but in mvc it's the first time I'm using it and it's not working. – arash moeen Apr 09 '14 at 13:58
-
So There is a "Web References" folder and files are there, right click on the folder and choose "Open folder in explorer" – Reza Apr 09 '14 at 14:01
-
Sorry my bad It's a WCF service, so there's a service reference folder in my solution explorer not a web reference. – arash moeen Apr 09 '14 at 14:16
-
-
Yea but it's empty inside, All I did was "right click on project" -> "Add service reference" -> "fill address with http://87.107.121.54/post/send.asmx and clicked ok" but I can't use it to create an object. What am I doing wrong? – arash moeen Apr 12 '14 at 06:00
-
I followed this http://www.naveenbhat.in/2013/07/mvc-4-wcf-add-service-reference.html but it didn't help, still got an empty reference.cs – arash moeen Apr 12 '14 at 06:04
Another commonly overlooked issue is that the service reference appends the root namespace of your project to the namespace you provide in the service configuration.
In other words, if the namespace of your service is ServiceReference1, the actual namespace that will be created will be [RootNameSpace].ServiceReference1. RootNameSpace is usually the name of your project, so in most cases you can fix it simply by appending your service reference with your [projectname.]. If the name of your project is MyProject, then the namespace will be MyProject.ServiceReference1
It is also fairly simple to open the csproj (assuming C# project) file in notepad and search for "RootNamespace" to find the root namespace for the project.

- 1,099
- 12
- 29