我设法重现了测试项目中的一个错误,其结构与我的生产代码类似.它由三个简单的项目组成:
通用(类库):
namespace Common
{
public enum PrimaryColor
{
Red,
Green,
Blue
};
}
Run Code Online (Sandbox Code Playgroud)
库(WCF服务库),它引用了Common:
using Common;
namespace Library
{
[ServiceContract]
public interface ILibrary
{
[OperationContract]
PrimaryColor GetColor();
}
public class Library : ILibrary
{
public PrimaryColor GetColor()
{
return PrimaryColor.Red;
}
}
}
Run Code Online (Sandbox Code Playgroud)
ClientApp(控制台应用程序),其中包含对Common的引用,以及对Library的服务引用,称为"LibraryServiceReference":
using Common;
using ClientApp.LibraryServiceReference;
namespace ClientApp
{
class Program
{
static void Main(string[] args)
{
LibraryClient client = new LibraryClient("WSHttpBinding_ILibrary");
PrimaryColor color = client.GetColor();
}
}
}
Run Code Online (Sandbox Code Playgroud)
ClientApp和Library中的app.config文件是自动生成的,我没有修改它们,我没有更改ClientApp中LibraryServiceReference的默认配置.
编译此解决方案时,我在ClientApp项目中收到以下错误:
错误1
'PrimaryColor' is an ambiguous reference between 'Common.PrimaryColor' and 'ClientApp.LibraryServiceReference.PrimaryColor'
Run Code Online (Sandbox Code Playgroud)
错误2
Cannot implicitly convert type 'ClientApp.LibraryServiceReference.PrimaryColor' to 'Common.PrimaryColor'. An explicit conversion exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
Ber*_* IT -2
在进行服务引用时,是否有一些选项类似于:“在生成的服务合同中包含常见类型”?
我的想法是,在您的服务引用中,类被“复制”,这就是您收到此错误的原因。检查生成的服务文件,然后删除并使用“添加服务引用”再次添加它们,然后查看其中有哪些选项。
编辑
尽管我几乎可以肯定 Type PrimaryColor 被定义了两次。一次在公共项目中,一次在服务参考中,您还可以在 clientApp 中尝试此操作(以更明确地指定 PrimaryColor 类型):
Common.PrimaryColor color = client.GetColor();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5254 次 |
| 最近记录: |