简体   繁体   English

C#从xsd创建包含数字签名的数据集

[英]C# Creating dataset from xsd containing digital signature

Visual Studios 2005, .NET 2.0 Visual Studios 2005,.NET 2.0

I'm working on a messaging service that sends and receives xml messages based on a 3rd party schema file I can't modify. 我正在开发一个消息传递服务,该服务基于无法修改的第三方模式文件发送和接收xml消息。 (I've verified the schema as valid and generated a sample xml message using Altova's XMLSpy.) The best solution I've found to handle this requirement is to create a dataset based on the schema and then populate the dataset using DataSet.ReadXml(). (我已经验证了该模式是有效的,并使用Altova的XMLSpy生成了示例xml消息。)找到满足此要求的最佳解决方案是基于该模式创建数据集,然后使用DataSet.ReadXml( )。 DataSet.WriteXml() should then be able to be used when creating messages. 然后,在创建消息时应该可以使用DataSet.WriteXml()。

When I've built DataSets off .xsd files in the past I've used the MSDataSetGenerator Custom Tool. 过去,我已经根据.xsd文件构建了DataSets,然后使用了MSDataSetGenerator自定义工具。 However the schema file I have errors out when running it through the MSDataSetGenerator with the error: 但是,通过MSDataSetGenerator运行具有错误的架构文件时出现错误:

Custom tool error: Failed to generate code. 自定义工具错误:无法生成代码。 Unable to convert input xml file content to a DataSet. 无法将输入的xml文件内容转换为数据集。 The 'http://www.w3.org/2000/09/xmldsig#:KeyInfo' element is not declared. 未声明“ http://www.w3.org/2000/09/xmldsig#:KeyInfo”元素。

Below are the lines relevant to the digital signatures/KeyInfo/Signature from the schema file. 以下是与模式文件中的数字签名/ KeyInfo / Signature相关的行。

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

Further on in the file it references 2 objects defined in that schema: 在文件中,它进一步引用了该模式中定义的2个对象:

<xs:element ref="ds:Signature" minOccurs="0"/>
<xs:element ref="ds:KeyInfo" minOccurs="0"/>

I've also tried loading the schema in by doing: 我还尝试通过以下方式加载架构:

DataSet ds = new DataSet();
ds.ReadXmlSchema("schema.xsd");

But that also throws the same error regarding KeyInfo not being declared. 但是,这也引发了与未声明KeyInfo相同的错误。

Is there another way to create the Dataset I'm missing or an option I need to set to be able to use the MSDataSetGenerator? 有没有其他方法可以创建我丢失的数据集,或者需要设置一个选项才能使用MSDataSetGenerator? Or does anyone know a better way to set this up overall instead of using a dataset based on the provided schema? 还是有人知道更好的方法来进行整体设置,而不是使用基于提供的模式的数据集?

The original XML Signature schema file from W3C contains a DTD header at the top, I guess to make compatible with older XML parsers. 来自W3C的原始XML签名架构文件在顶部包含一个DTD标头,我想使其与旧的XML解析器兼容。 Apparently the .Net schema reader doesn't like that. 显然.Net模式阅读器不喜欢这样。 The easiest solution is to comment out the eight lines from 最简单的解决方案是从中注释掉八行

<!DOCTYPE ...

to ]> . ]>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM