can't access the added service reference

39,380

Solution 1

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!

Solution 2

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

Solution 3

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

Solution 4

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.

Share:
39,380
arash moeen
Author by

arash moeen

Updated on May 21, 2021

Comments

  • arash moeen
    arash moeen almost 3 years

    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
    arash moeen about 10 years
    The class name is "BaseJob" with namespace "SmsPanel, the service reference namespace is "ServiceReference1"...
  • arash moeen
    arash moeen about 10 years
    Where exactly can I access this proxy class ?
  • arash moeen
    arash moeen about 10 years
    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 ???
  • Reza
    Reza about 10 years
    There is a ServiceReference folder in your solution and generated files are there
  • arash moeen
    arash moeen about 10 years
    If you're talking about the service reference folder in my solution then there's nothing there than my service references.
  • Reza
    Reza about 10 years
    @arashmoeen is it a WEB Service or a WCF Service?
  • arash moeen
    arash moeen about 10 years
    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.
  • Reza
    Reza about 10 years
    So There is a "Web References" folder and files are there, right click on the folder and choose "Open folder in explorer"
  • Reza
    Reza about 10 years
    if you have added the reference via visual studio it will add necessary things in web.config by it self
  • arash moeen
    arash moeen about 10 years
    well it didn't add anything in my webconfig and that's the problem.
  • arash moeen
    arash moeen about 10 years
    Sorry my bad It's a WCF service, so there's a service reference folder in my solution explorer not a web reference.
  • Reza
    Reza about 10 years
    So did you find the reference.cs ?
  • arash moeen
    arash moeen about 10 years
    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?
  • arash moeen
    arash moeen about 10 years
    I followed this naveenbhat.in/2013/07/mvc-4-wcf-add-service-reference.html but it didn't help, still got an empty reference.cs
  • Manoj Attal
    Manoj Attal over 9 years
    It worked for me as well. But does anybody no, what is its significance and why it worked?
  • Leonidas
    Leonidas almost 9 years
    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!
  • Chakri
    Chakri over 8 years
    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 :(
  • sohaiby
    sohaiby over 6 years
    worked for me in VS 2015.Would love to know the reasoning of this solution
  • Marius Popa
    Marius Popa over 5 years
    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.
  • BunkerBilly
    BunkerBilly almost 5 years
    Thank you! so much time wasted!