32

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?

arash moeen
  • 4,533
  • 9
  • 40
  • 85

4 Answers4

82

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!

Cœur
  • 37,241
  • 25
  • 195
  • 267
arash moeen
  • 4,533
  • 9
  • 40
  • 85
8

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

Sai Avinash
  • 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
  • 1
    I 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
2

Look at the proxy class that is generated by visual studio for your service and see what is the namespace and the class name

Reza
  • 18,865
  • 13
  • 88
  • 163
  • 1
    Where exactly can I access this proxy class ? – arash moeen Apr 09 '14 at 13:13
  • 1
    There 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
  • @arashmoeen is it a WEB Service or a WCF Service? – Reza Apr 09 '14 at 13:42
  • 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
  • So did you find the reference.cs ? – Reza Apr 09 '14 at 15:56
  • 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
2

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.

Achilles
  • 1,099
  • 12
  • 29