【问题标题】:Getting namespace error while adding service reference of 1 wcf service in another wcf service在另一个 wcf 服务中添加 1 个 wcf 服务的服务引用时出现命名空间错误
【发布时间】:2017-01-20 10:26:12
【问题描述】:

我有 2 个 wcf 服务作为单独的项目:

1) 区域服务

2) 国家服务

项目名称 = RegionService

IRegionService.cs
IRegionService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="RegionService.RegionService" CodeBehind="RegionService.svc.cs" %>

项目名称 = CountryService

ICountryService.cs
CountryService.svc
<%@ ServiceHost Language="C#" Debug="true" Service="CountryService.CountryService" CodeBehind="CountryService.svc.cs" %>

现在我想使用 Country Service 中的 RegionService 方法,因此我在 CountryService wcf 项目中提供了 RegionService 的服务参考,但是当我构建项目时出现错误:

类型中不存在类型名称“ServiceReference1” 'CountryService.CountryService'

我猜这是因为项目名称和 svc 文件名冲突,因为以前当我的 svc 文件名与项目名称不同时,我能够成功添加服务引用。

那么有什么解决方法吗?我不想更改我的文件或项目的名称,因为这会导致很多地方发生变化。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    当您添加 ServiceReference 时,将默认命名空间 ServiceReference1 更改为 CountryReference 之类的其他名称以解决冲突命名空间问题。

    您正在使用 ServiceReference1 作为两个服务的命名空间

    【讨论】:

    • 尝试删除引用类,使用新命名空间再次添加servicereference,清理并重建
    • 赞成您为帮助我所做的努力,非常感谢您帮助我。查看我的回答,我是如何解决这个问题的
    【解决方案2】:

    经过一番研究,我想出了以下成功的解决方法:

    using AliasCountryService = global::CountryService.ServiceReference1;
    

    所以现在我用AliasCountryService 替换了所有CountryService.ServiceReference1,这解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 2011-04-20
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-07
      相关资源
      最近更新 更多