WCF XML 反序列化对命名空间和别名非常挑剔

编程入门 行业动态 更新时间:2024-10-21 20:36:13
本文介绍了WCF XML 反序列化对命名空间和别名非常挑剔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在编写一个 WCF SOAP 服务,试图与 Java 客户端集成.这个过程有点不寻常,因为客户端已经指定了WSDL,我必须创建一个可以接受他们请求的服务.

I am writing a WCF SOAP service, trying to integrate with a Java client. The process is a bit unusual, because the client has specified the WSDL, and I have to create a service which can accept requests from them.

当我们尝试执行集成时,我得到了一些非常挑剔的结果.非常细微的差异(在我看来似乎没问题)导致 XML 反序列化失败.

Im getting some very finicky results when we try to perform the integration. Very subtle differences (that appear to be ok to my eyes) cause the XML deserialization to fail.

这是客户端实际生成的 XML,它最终为我提供了 CCHNameSearchResponse 的所有子属性的空值,例如,在 XML 中设置为999"的 InterfaceControlField 遇到了空)

This is the XML actually produced by the client, which ends up giving me null values for all the child properties of CCHNameSearchResponse for example, the InterfaceControlField which is set to "999" in the XML comes across empty)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap/soap/envelope/" xmlns:urn="urn:soapclienth.doj.state.wi.us">
   <soapenv:Header/>
   <soapenv:Body>
      <impl:CCHNameSearchResponse xmlns:impl="urn:soapclienth.doj.state.wi.us" xmlns:xsi="http://www.w3/2001/XMLSchema-instance">
         <InterfaceControlField>999</InterfaceControlField>

这个有效,唯一的区别是命名空间别名 (xmlns:impl=) 在我看来它是可以接受的?

This one works, the only difference is the namespace alias (xmlns:impl=) which to my eyes looks like it acceptable?

xmlns:urn="urn:soapclienth.doj.state.wi.us">
   <soapenv:Header/>
   <soapenv:Body>
      <CCHNameSearchResponse xmlns="urn:soapclienth.doj.state.wi.us" xmlns:xsi="http://www.w3/2001/XMLSchema-instance">
         <InterfaceControlField xmlns="">999</InterfaceControlField>

为什么?我怎样才能让它接受生成的 XML?

推荐答案

问题是如果没有别名,命名空间将成为所有子元素的默认命名空间.

The issue is that without an alias, the namespace becomes the default namespace for all child elements.

使用别名,子元素位于无命名空间"中,因此在序列化中没有被正确选取.

With the alias, the child elements are in the "no-namespace", and therefore are not picked up correctly in the serialization.

这是每个规范,因此为我生成 XML 的方面存在问题.

This is per spec, so its a problem with the side generating the XML for me.

http://www.w3/TR/xml-names/#违约

因此,要么不使用别名(根据 OP 中的第二个示例),要么必须在任何地方使用别名,如此处的示例所示

So either no alias should be used (per the second example in the OP) or the alias must be used everywhere, as in the sample here

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap/soap/envelope/" xmlns:urn="urn:soapclienth.doj.state.wi.us">
   <soapenv:Header/>
   <soapenv:Body>
      <impl:CCHNameSearchResponse xmlns:impl="urn:soapclienth.doj.state.wi.us" xmlns:xsi="http://www.w3/2001/XMLSchema-instance">
         <impl:InterfaceControlField>999</impl:InterfaceControlField>

这篇关于WCF XML 反序列化对命名空间和别名非常挑剔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:26:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141102.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   挑剔   序列化   空间   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!