tags:

views:

2265

answers:

3

I have a .xsd file which I use to generate code with the xsd.exe tool from Visual Studio. Some class members are Guids and the xsd.exe tool gives 2 warnings:

Namespace 'http://microsoft.com/wsdl/types/' is not available to be referenced in this schema. Type 'http://microsoft.com/wsdl/types/:guid' is not declared.

The Guid type is recognized because the generated C# file is valid and works. Anyone knows how to get rid of those warnings?

What is the correct syntax for the XSD to be validated AND class members being generated as System.Guid?

+1  A: 

It looks like that wsdl namespace extension page was deleted, so it can't find the type information you need.

sysrqb
+1  A: 

Citation from here:

   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");
boj
Thank you, as I understand, I have to roll up my own schema for the Guid type to replicate what the wsdl namespace does.This is C# code however, how do I put this into my XSD file so xsd.exe can read it?
Kovey
I think, you can't extend xsd.exe in this way. But may you are able to generate schema with .NET, without xsd.exe based on this code snippet.Or, other xsd.exe alternatives: http://www.hitsw.com/xml_utilites/I'll google for complete .NET implementation.
boj
+3  A: 

Thank you all, I found how to remove the warnings.

As sysrqb said, the wsdl namespace has either been deleted or never existed. It seems that the xsd.exe tool knows the Guid definition internally, but it cannot validate the xsd schema.

As boj pointed out, the only way to validate the schema with Guids in it, is to (re)define that type in a schema. The trick here is to add the Guid type to the same "http://microsoft.com/wsdl/types" namespace. This way, the xsd.exe will do the proper association between http://microsoft.com/wsdl/types:Guid and System.Guid

I made a new xsd file for the guid type:

<?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>

Then, I run xsd.exe with both my original xsd file and this new xsd file:

xsd.exe myschema.xsd guid.xsd /c
Kovey