Skip to main content
 首页 » 编程设计

c#之无法通过 "using"使用命名空间

2024年02月20日16daizhj

我有以下工作代码(用于使用 WCF 服务)。

SecurityRoleWebService is a namespace.

SecurityWebserviceManagerImplClient is a class corresponding to a WCF service.

getSecurityRoles() is a method corresponding to service operation.

当我将命名空间添加为

using SecurityRoleWebService  

我收到以下错误:

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

为什么会这样?如何克服这个问题?

SecurityRoleWebService.SecurityWebserviceManagerImplClient proxySecurityRole = new SecurityRoleWebService.SecurityWebserviceManagerImplClient(); 
 
        SecurityRoleWebService.SecurityRole[] roles = proxySecurityRole.getSecurityRoles(userID); 
 
        string roleName = roles[0].roleName; 

请您参考如下方法:

您在其中创建 ServiceReference 的项目的命名空间是什么?您可能需要在使用中为该 namespace 添加“前缀”:

using YourNamespaceHere.SecurityRoleWebService;