简体   繁体   English

在另一个WCF服务中添加1个WCF服务的服务引用时出现名称空间错误

[英]Getting namespace error while adding service reference of 1 wcf service in another wcf service

I am having 2 wcf services as separate project: 我有2个wcf服务作为单独的项目:

1) RegionService 1)RegionService

2) CountryService 2)CountryService

Project name = RegionService 项目名称= RegionService

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

Project name = CountryService 项目名称= CountryService

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

Now I would like to consume methods of Region service from Country Service so I have give service reference of RegionService in my CountryService wcf project but when I build the project I get error: 现在,我想使用Country Service中的Region服务方法,因此我在CountryService wcf项目中提供了RegionService的服务引用,但是在构建项目时出现错误:

The type name 'ServiceReference1' does not exist in the type 'CountryService.CountryService' 类型名称“ ServiceReference1”在类型“ CountryService.CountryService”中不存在

I guess this is happening because of conflicting project name and svc file name as because previously when my svc file name was different from project name I was able to add service reference successfully. 我猜这是由于项目名和svc文件名冲突而发生的,因为以前当我的svc文件名不同于项目名时,我能够成功添加服务引用。

在此处输入图片说明

So is there any workaround for this? 那么有什么解决方法吗? I don't want to change name of my files or project as this would lead to changes at lots of places. 我不想更改文件或项目的名称,因为这会导致很多地方的更改。

在此处输入图片说明

When you add ServiceReference change default namespace ServiceReference1 to something else like CountryReference to fix conflict namespace problem. 当您添加ServiceReference更改默认的命名空间ServiceReference1别的东西像CountryReference解决冲突的命名空间的问题。

you are using ServiceReference1 as namespace for both services 您正在使用ServiceReference1作为两个服务的名称空间

After a bit research i came up to this below workaround which worked successfully : 经过一些研究,我得出以下成功解决的方法:

using AliasCountryService = global::CountryService.ServiceReference1;

So now i have replace all CountryService.ServiceReference1 with AliasCountryService which solved my issue. 所以我现在所取代所有CountryService.ServiceReference1AliasCountryService这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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