can't access the added service reference
Asked Answered
D

4

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?

Duron answered 9/4, 2014 at 13:2 Comment(0)
D
84

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!

Duron answered 12/4, 2014 at 6:24 Comment(7)
It worked for me as well. But does anybody no, what is its significance and why it worked?Pheidippides
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!Pugh
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 :(Prom
worked for me in VS 2015.Would love to know the reasoning of this solutionRapp
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.Petiolate
Thank you! so much time wasted!Derringer
Just to add to that I found a reboot of my VS was requiredTessietessier
S
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

Sharla answered 9/4, 2014 at 13:5 Comment(4)
The class name is "BaseJob" with namespace "SmsPanel, the service reference namespace is "ServiceReference1"...Duron
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 ???Duron
if you have added the reference via visual studio it will add necessary things in web.config by it selfCheckbook
well it didn't add anything in my webconfig and that's the problem.Duron
C
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

Checkbook answered 9/4, 2014 at 13:6 Comment(10)
Where exactly can I access this proxy class ?Duron
There is a ServiceReference folder in your solution and generated files are thereCheckbook
If you're talking about the service reference folder in my solution then there's nothing there than my service references.Duron
@arashmoeen is it a WEB Service or a WCF Service?Checkbook
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.Duron
So There is a "Web References" folder and files are there, right click on the folder and choose "Open folder in explorer"Checkbook
Sorry my bad It's a WCF service, so there's a service reference folder in my solution explorer not a web reference.Duron
So did you find the reference.cs ?Checkbook
Yea but it's empty inside, All I did was "right click on project" -> "Add service reference" -> "fill address with 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?Duron
I followed this naveenbhat.in/2013/07/mvc-4-wcf-add-service-reference.html but it didn't help, still got an empty reference.csDuron
O
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.

Opine answered 19/8, 2016 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.