我目前正在开发一个基于 c# 的 webapp,它调用一些 web 服务。我已从提供程序中将三个不同的 WSDL 导入到我的 WebApplication3 项目中(引用 -> 添加 Web 引用)。在类查看器中,它们显示为:

WebApplication3.com.provider.webservices1
WebApplication3.com.provider.webservices2
WebApplication3.Properties

显然,第一个和第二个 WSDL 具有重复的功能(这是正确的名称吗?)

如果我将以下内容添加到我的 Default.aspx.cs 中:

使用 WebApplication3.com.sabre.webservices1;
使用 WebApplication3.com.sabre.webservices2;
使用 WebApplication3.Properties;

然后尝试使用:

MessageHeader msgHeader = new MessageHeader();
在我的 WebApplication3 命名空间中,出现错误

“WebApplication3.com.provider.webservices1 和
WebApplication3.com.provider.webservices2"

我想这是因为它在两个 WSDL 中都声明了?我该如何解决这个问题,以便我可以使用它?

谢谢,如果问题很愚蠢,我很抱歉!

最佳答案

尝试使用其完整命名空间来引用 MessageHeader。
例如。

WebApplication3.com.provider.webservices1.MessageHeader msgHeader = new
WebApplication3.com.provider.webservices1.MessageHeader()

为简洁起见,您可以尝试
using MessageHeader = WebApplication3.com.provider.webservices1.MessageHeader

这会让你使用
MessageHeader msgHeader = new MessageHeader()

其中 MessageHeader 来自 webservices1 命名空间

关于c# - 在 C# 中引用多个 Web 服务时解决类型歧义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/778877/

10-13 00:57