简体   繁体   中英

can't access the added service reference

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?

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!

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

查看visual studio为你的服务生成的代理类,看看命名空间和类名是什么

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM