27

Visual Studio の xsd.exe ツールでコードを生成するために使用する .xsd ファイルがあります。一部のクラス メンバーは Guid であり、xsd.exe ツールは次の 2 つの警告を表示します。

名前空間 ' http://microsoft.com/wsdl/types/ ' は、このスキーマで参照できません。タイプ ' http://microsoft.com/wsdl/types/:guid ' が宣言されていません。

生成された C# ファイルが有効で機能するため、Guid 型が認識されます。これらの警告を取り除く方法を知っている人はいますか?

XSD が検証され、クラス メンバーが System.Guid として生成されるための正しい構文は何ですか?

4

3 に答える 3

47

ありがとうございました。警告を削除する方法を見つけました。

sysrqbが言ったように、wsdl 名前空間は削除されたか、存在しませんでした。xsd.exe ツールは内部的に Guid 定義を認識しているようですが、xsd スキーマを検証できません。

bojが指摘したように、Guid を含むスキーマを検証する唯一の方法は、スキーマでその型を (再) 定義することです。ここでの秘訣は、Guid 型を同じ " http://microsoft.com/wsdl/types " 名前空間に追加することです。このように、xsd.exe はhttp://microsoft.com/wsdl/types:Guidと System.Guidの間の適切な関連付けを行います。

guid タイプの新しい xsd ファイルを作成しました。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://microsoft.com/wsdl/types/" >
    <xs:simpleType name="guid">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                The representation of a GUID, generally the id of an element.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

次に、元の xsd ファイルとこの新しい xsd ファイルの両方で xsd.exe を実行します。

xsd.exe myschema.xsd guid.xsd /c
于 2009-04-06T20:20:34.453 に答える
3

ここからの引用:

   XmlSchema guidSchema = new XmlSchema();
   guidSchema.TargetNamespace = "http://microsoft.com/wsdl/types/";

   XmlSchemaSimpleTypeRestriction guidRestriction = new XmlSchemaSimpleTypeRestriction();
   guidRestriction.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);

   XmlSchemaPatternFacet guidPattern = new XmlSchemaPatternFacet();
   guidPattern.Value = @"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
   guidRestriction.Facets.Add(guidPattern);

   XmlSchemaSimpleType guidType = new XmlSchemaSimpleType();
   guidType.Name = "guid";
   guidType.Content = guidRestriction;
   guidSchema.Items.Add(guidType);

   schemaSet.Add(guidSchema);

   XmlSchema speakerSchema = new XmlSchema();
   speakerSchema.TargetNamespace = "http://www.microsoft.com/events/teched2005/";

   // ...

   XmlSchemaElement idElement = new XmlSchemaElement();
   idElement.Name = "ID";

   // Here's where the magic happens...

   idElement.SchemaTypeName = new XmlQualifiedName("guid", "http://microsoft.com/wsdl/types/");
于 2009-03-26T23:16:47.590 に答える
1

その wsdl 名前空間拡張ページが削除されたようです。そのため、必要な型情報が見つかりません。

于 2009-03-26T23:10:12.553 に答える