Xsd2Code 和 xmldsig [英] Xsd2Code and xmldsig

查看:23
本文介绍了Xsd2Code 和 xmldsig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Xsd2Code 从 xsd 生成代码时遇到问题.xsd 看起来像这样:

I have a problem with generating code from xsd with Xsd2Code. The xsd looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:CountryIdentificationCode-1.0"
           xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:LocationIdentificationCode-1.0"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">

  <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig.xsd" />

  .......

</xs:schema>

当我尝试序列化生成的类的实例时遇到的错误:

The error I fet when I try to serialize the instance of a generated class:

"Cannot serialize object of type 'MyXSD.SignatureValueType'. 
 Consider changing type of XmlText member 'MyXSD.SignatureValueType.Value' from System.Byte[] to string or string array."

错误发生在这里:

[System.Xml.Serialization.XmlTextAttribute(DataType = "base64Binary")]
public byte[] Value
{
    get
    {
        return this.valueField;
    }
    set
    {
        this.valueField = value;
    }
}

如果我将该属性更改为:

Event if I change that attribute to:

[System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")]

...我收到其他错误:

..i get other error:

Type of choice identifier 'ItemsElementName' is inconsistent with type of 'Items'.
Please use array of System.Collections.Generic.List`1[[MyXSD.ItemsChoiceType2, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

有没有人成功地将 Xsd2Code 与 xmldsig 一起使用?如果可能的话,我宁愿使用 Xsd2Code 生成器而不是手动解决这个问题.还有其他选择吗?

Did anybody successfully use Xsd2Code with xmldsig? If possible I would rather solve this with Xsd2Code generator and not manually. Is there any other option?

推荐答案

在 Xsd2Code 选项中,将选项 'CollectionObjectType' 设置为 'Array' 而不是 'List'.

In Xsd2Code options, set option 'CollectionObjectType' as 'Array' instead of 'List'.

这篇关于Xsd2Code 和 xmldsig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆