- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Visual Studio 2013 从 this WSDL file 生成 WCF 服务代理。然而,当我尝试调用 setSalesItemsV3
方法,WCF 抛出 InvalidOperationException
来自深处System.Xml.dll
.
此示例项目演示了该问题:https://github.com/jennings/WsdlDuplicateNameProblem
这是内部异常:
Message: The top XML element 'start' from namespace '' references distinct types WsdlDuplicateName.SalesItemService.hsSimpleDate and System.DateTime. Use XML attributes to specify another XML name or namespace for the element or types.
我不是阅读 WSDL 的专家,但我看过它,唯一引用名称“start”的部分是几个 <wsdl:part>
具有 name="start"
的元素:
<wsdl:message name="setSalesItems">
<wsdl:part name="start" type="xsd:dateTime"></wsdl:part>
</wsdl:message>
<wsdl:message name="setSalesItemsV3">
<wsdl:part name="start" type="tns:hsSimpleDate"></wsdl:part>
</wsdl:message>
但是,这些部分处于完全不同的消息中,所以我不明白为什么会有任何混淆。我已经通过几个在线 WSDL 验证器运行了 WSDL 文件,他们似乎对此表示满意。
下面是项目中重现问题所需的唯一代码(除了生成的代理之外)。
class Program
{
static void Main(string[] args)
{
SalesServiceClient client = new SalesServiceClient();
var date = ToSimpleDate(new DateTime());
// throws InvalidOperationException
// Message == "There was an error reflecting 'start'."
client.setSalesItemsV3(1, 1, null, date, date);
}
static hsSimpleDate ToSimpleDate(DateTime time)
{
return new hsSimpleDate
{
year = time.Year,
month = time.Month,
day = time.Day,
};
}
}
最佳答案
为了演示该问题,让我们看一下生成的 Reference.cs:
public partial class getSalesItemsV3 {
// skipped
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=2)]
public WsdlDuplicateName.SalesItemService.hsSimpleDate start;
// skipped
}
public partial class setSalesItems {
// skipped
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=3)]
public System.DateTime start;
// skipped
}
请注意,这些元素具有相同的名称 (start
) 和由 MessageBodyMember 属性声明的相同命名空间(""
,空命名空间)。这会导致“来自命名空间''的顶部 XML 元素'start'引用不同类型”序列化程序异常。
如果我们有这个选项:
(b) the changes I can make to the generated proxies to make the serializer happy
...我们可以手动为元素 start
、end
和 return
设置命名空间(它们都会引起麻烦)。我自己做了,把结果here 。您可以将其粘贴到 Reference.cs 中,序列化器异常就会消失。
但问题的根本原因似乎是该服务( http://services.hotschedules.com/api/services/SalesService?wsdl )旨在通过 WebServices 使用(并且此问题是某种不兼容)。
如果您添加对此服务器的引用作为 Web 引用(添加 -> 服务引用... -> 高级... -> 添加 Web 引用...)并编写相同的 Web 方法调用,不会出现序列化问题。实际上,就我而言,我在测试示例中收到了另一种服务器异常,但它将解决您的直接序列化问题。
可以找到代码的镜像副本,但使用 Web 服务引用(并且不需要对生成的文件进行任何更改)here .
希望这会有所帮助。
更新:要找到导致此问题的真正原因,我们需要深入研究 XmlReflectionImporter
源代码。首先,我们的 WSDL 使用 XSD 模式来定义 namespace : http://www.w3.org/2001/XMLSchema 对于 xsd
和 http://services.hotschedules.com/api/services/SalesService 为tns
。 XmlReflectionImporter
使用 NameTable
(这是 Hashtable
的包装器)来存储“访问器”。访问器是一对 Namespace
和 Name
。
让我们看看抛出异常的源代码:
private Accessor ReconcileAccessor(Accessor accessor, NameTable accessors)
{
// initial check skipped
// look for accessor by name and namespace, add to accessors hash if not found and return
Accessor accessor1 = (Accessor) accessors[accessor.Name, accessor.Namespace];
if (accessor1 == null)
{
accessor.IsTopLevelInSchema = true;
accessors.Add(accessor.Name, accessor.Namespace, (object) accessor);
return accessor;
}
// accessor ("start" in our case) found!
// check if mappings is the same and return accessor. This is not our case, we have two accessors with the same name but different mappings (despite that this mappings is have the same type)!
if (accessor1.Mapping == accessor.Mapping)
return accessor1;
// next I skipped some reconciliations for MembersMapping and ArrayMapping. Please note that it performed by types, for example:
// if (accessor.Mapping is ArrayMapping) { /* some logic */}
// Our mapping is not MembersMapping or ArrayMapping and we finally got there:
throw new InvalidOperationException(Res.GetString("XmlCannotReconcileAccessor", (object) accessor.Name, (object) accessor.Namespace, (object) XmlReflectionImporter.GetMappingName((Mapping) accessor1.Mapping), (object) XmlReflectionImporter.GetMappingName((Mapping) accessor.Mapping)));
// Resource definition is: XmlCannotReconcileAccessor=The top XML element '{0}' from namespace '{1}' references distinct types {2} and {3}. Use XML attributes to specify another XML name or namespace for the element or types.
// using this resource template you can see that string representations of mappings are "WsdlDuplicateName.SalesItemService.hsSimpleDate" and "System.DateTime".
}
所以,主要的协调逻辑是我们不能有两个具有相同名称但不同命名空间的访问器! MembersMapping
和 ArrayMapping
类型可能存在一些异常(exception),但这不是我们的情况。
我相信这是某种错误。 WSDL 是正确的并且将通过验证,但由于来自 XmlReflectionImporter
类的 ReconcileAccessor
的通用实现,我们遇到了异常。不确定这是否是 XmlReflectionImporter
的确切问题,或者可能是更高抽象层上存在另一个问题。并且,“Web Reference”生成的源代码未使用 XmlReflectionImporter
。
还有一件事值得一提:生成器为 MessageBodyMemberAttribute 添加一个 Namespace=""
值,这实际上破坏了协调过程。因此,我认为存在一些不一致或不兼容的情况。
关于由于 WSDL 中存在多个同名类型,WCF 生成的代理抛出 InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29132014/
为什么 WSDL 引入 wsdl:message?和消息部分? 与在操作参数(输入、输出、故障)中直接使用 XSD 相比,他们可以带来什么优势? 它们(带有 wsdl 消息部分的 wsdl 消息)如何
这个问题看起来很简单,但我找不到合适的地方在 WSDL 文档中设置其定义的版本。 目标是能够很容易地看到它何时过时,以及我将来何时更新它。 我要把它设为 1.0。如果将来我向它添加新操作,我将其设置为
在 WSDL 文件中,函数可以返回类型或元素。到目前为止,我仅使用自定义类型作为结果。但是,我想知道什么时候Element应该比Type更合适?它们有什么区别? 有什么区别吗 和
我在 web sphere 服务器上部署了一个 jax-ws web 服务,当我尝试使用 url 在浏览器中访问 wsdl 时 "Http://localhost:7001/HelloWorldSer
我在使用 SVCUtil 为 WCF 生成代理时遇到错误。错误是 Attempting to download metadata from 'net.pipe://localhost/WebServi
我正在遵循 WSDL-first(由我们的客户提供)方法来开发 WCF 服务,但是从我的 wcf 服务生成的 WSDL 与我们的客户提供给我的 WSDL 略有不同,并且由于这种不匹配,客户在调用我的服
我有嵌套的 WSDL,我想将其扁平化。 wsdl 导入 xsd 文件,这些文件又包含其他文件等。我喜欢把整个东西压平成一个文件,以便将它提供给一个无法执行导入/包含的工具。有没有我可以使用的简单工具(
我正在尝试使用一些统计信息进行 WSDL 解析(使用 c#.net)。我的统计数据取决于 WSDL 中的文档标签。我想知道可以包含文档标签的 wsdl 标签列表来检查它们。 我试图阅读 WS-I 基本
我有一个 WSDL 文件。我想将 wsdl 文件转换为 Web 服务类文件。 是否可以?如果是,请向我详细解释。 最佳答案 在解决方案资源管理器中右键单击 您的项目并转到“添加服务 引用...” 按窗
我正在使用 Axis 为示例 WebService 建模。我现在正在做的是试图了解自动化 wsdl 和代码生成的局限性。 现在对于一些服务器端代码: 这是示例 Web 服务的框架: public cl
我有一个 Silverlight 应用程序,它通过 WCF 服务与服务器端的 ADO.Net 数据实体通信。实际上,我正在使用多个 WCF 服务与三个不同的数据 ADO.Net 数据实体进行通信。我最
是否有使用服务端点地址获取服务 WSDL 的通用方法。我知道这可以通过将 ?wsdl 附加到 Axis2 服务来完成。但是这个属性是否也适用于其他 Web 服务容器? 最佳答案 ?wsdl 适用于所有
例如使用 png归档其 mime-type是“图像/png”;那么 wsdl 的 MIME 类型是什么?文件 ? 最佳答案 text/xml - WSDL 是基于 XML 格式的服务描述。 您可以在“
我的服务是从一个 wsdl 文件中选取的。但是发布的服务 wso2 是 chenged。如果我希望 wso2 像我的 wsdl 文件一样发布。如何设置?例如,我的 wsdl 文件是:
我需要在给定 XSD 文件的情况下生成 WSDL 文件。我该怎么做呢?我可以在VS2005中这样做吗?最简单的方法是什么? 最佳答案 你不能 - XSD 描述数据方面,例如Web 服务的功能 - WS
有什么方法可以从 wsdl 生成 xsd 吗?任何链接或工具也可以。最简单的方法是什么? 最佳答案 您可以使用SoapUI:http://www.soapui.org/这是一个通常很方便的程序。创建一
我启动我的 azure 应用程序,浏览到 svc 文件 http://127.0.0.1:82/transaction.svc ,我得到了通常的结果: You have created a servi
我使用动态端点 wsdl(通过 http 的 wsdl)来生成客户端。这工作得很好。 是否可以从动态wsdl的http链接生成静态wsdl? 问题是动态 wsdl 只能从一台机器访问。 我想在另一台电
我想知道是否可以将请求从一个 wsdl 发送到另一个 wsdl。如果是,那我该怎么做? 流程将是: 我想使用 switchyard 公开一个 wsdl,比如 wsdl-1,它可能有 100 个参数,带
我按照定义的步骤使用 Spring Boot 创建了一个网络服务 here当我尝试下载 wsdl 时,我不得不在 url 中使用 .wsdl 。但是,当我使用 ?wsdl 时,不会下载 wsdl。当我
我是一名优秀的程序员,十分优秀!