1

I have following working code (for consuming a WCF service).

SecurityRoleWebService is a namespace.

SecurityWebserviceManagerImplClient is a class corresponding to a WCF service.

getSecurityRoles() is a method corresponding to service operation.

When I add the namespace as

using SecurityRoleWebService 

I am getting the following error:

Error: The type or namespace name 'SecurityRoleWebService' could not be found (are you missing a using directive or an assembly reference?)

Why is it so? How to overcome this?

SecurityRoleWebService.SecurityWebserviceManagerImplClient proxySecurityRole = new SecurityRoleWebService.SecurityWebserviceManagerImplClient();

        SecurityRoleWebService.SecurityRole[] roles = proxySecurityRole.getSecurityRoles(userID);

        string roleName = roles[0].roleName;
Community
  • 1
  • 1
LCJ
  • 22,196
  • 67
  • 260
  • 418
  • 2
    Uhm is SecurityRoleWebService the full namespace? Isn't it prefixed by the namespace of your project? Have you tried the full namespace? – Hinek Aug 07 '12 at 12:29
  • 4
    Sorry to state the obvious, but it sounds like you need to referende the DLL where SecurityRoleWebService is defined. – Justin Harvey Aug 07 '12 at 12:29
  • @Hinek Thanks. Using my project's namespace as prefix to the web service's namespace did the fix. Could you please post it as answer? Also, can you please explain why my earlier code worked without my project's prefix? – LCJ Aug 07 '12 at 13:10
  • @Lijo You're welcome, I'm glad it helped and tried to explain it in the answer. Just ask, if there's still something unclear. – Hinek Aug 07 '12 at 13:21

3 Answers3

2

What's the namespace of the project you've created the ServiceReference in? You probably need to 'prefix' that namespace in your using:

using YourNamespaceHere.SecurityRoleWebService;
fguchelaar
  • 4,779
  • 23
  • 36
1

have you referenced the dll in your project ? If not, right-click on your project, then Add Reference and then select your dll.

h1ghfive
  • 196
  • 7
1

Use the full qualified namespace of the class. When you a using a ServiceReference, the generated namespace is [default namespace of your project].[name of the service reference]. You have to use this full qualified namespace in a using.

When you prefix a class like you did with new SecurityRoleWebService.SecurityWebserviceManagerImplClient(); you can use a relative namespace (relative to the namespace the codeblock is in).

When you write a using, this you are not in a codeblock that has a namespace, so there is no namespace to relate to. You have to use the full qualified namespace.

Hinek
  • 9,519
  • 12
  • 52
  • 74