I posted this message yesterday on a different group which may have been the
wrong group, so I am not cross posting on purpose.
Hi,
I have a question regarding how the .Net framework interprets schema
definitions based on existing types.
I have (for the purposes of demonstration) a very simple types schema which
contains some PersonName (T_PERSONNAME) and Address (T_ADDRESS) details as
below.
<?xml version="1.0" encoding="utf-16" ?>
- <xs:schema xmlns=http://com.test.schemas.BaseTypes
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
targetNamespace=http://com.test.schemas.BaseTypes
xmlns:xs="http://www.w3.org/2001/XMLSchema">
- <xs:element name="BaseTypes">
- <xs:complexType>
- <xs:sequence>
<xs:element name="PersonName" type="T_PERSONNAME" />
<xs:element name="AddressDetails" type="T_ADDRESS" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:complexType name="T_PERSONNAME">
- <xs:sequence>
<xs:element name="Forename" type="xs:string" />
<xs:element name="Surname" type="xs:string" />
<xs:element name="MiddleName" type="xs:string" />
</xs:sequence>
</xs:complexType>
- <xs:complexType name="T_ADDRESS">
- <xs:sequence>
<xs:element name="Address1" type="xs:string" />
<xs:element name="Address2" type="xs:string" />
<xs:element name="Address3" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
I use these types to define a "Person" with some extensions.
<?xml version="1.0" encoding="utf-16" ?>
- <xs:schema xmlns:typ=http://com.test.schemas.BaseTypes
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
xmlns=http://com.test.schemas.Person
targetNamespace=http://com.test.schemas.Person
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation=".\basetypes.xsd"
namespace=http://com.test.schemas.BaseTypes />
- <xs:annotation>
- <xs:appinfo>
- <b:references>
<b:reference targetNamespace=http://com.test.schemas.BaseTypes />
</b:references>
</xs:appinfo>
</xs:annotation>
- <xs:element name="Person">
- <xs:complexType>
- <xs:sequence>
<xs:element name="id" type="xs:string" />
- <xs:element name="PersonName">
- <xs:complexType>
- <xs:complexContent mixed="false">
- <xs:extension base="typ:T_PERSONNAME">
- <xs:sequence>
- <xs:element name="FathersName">
- <xs:complexType>
- <xs:sequence>
<xs:element name="Forename" type="xs:string" />
<xs:element name="Surname" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Alias" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I use the xsdobjectgen .Net add-in tool to create data structures to support
these schemas. These (to me) look fine
// Copyright 2004, Microsoft Corporation
// Sample Code - Use restricted to terms of use defined in the accompanying
license agreement (EULA.doc)
//--------------------------------------------------------------
// Autogenerated by XSDObjectGen version 1.4.2.1
// Schema file: Person.xsd
// Creation Date: 21/03/2006 15:14:03
//--------------------------------------------------------------
using System;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
namespace http___com_test_schemas_BaseTypes
{
public struct Declarations
{
public const string SchemaVersion = "http://com.test.schemas.BaseTypes";
}
[XmlType(TypeName="T_ADDRESS"),Serializable]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public class T_ADDRESS
{
[XmlElement(ElementName="Address1",IsNullable=false ,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Address1;
[XmlIgnore]
public string Address1
{
get { return __Address1; }
set { __Address1 = value; }
}
[XmlElement(ElementName="Address2",IsNullable=false ,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Address2;
[XmlIgnore]
public string Address2
{
get { return __Address2; }
set { __Address2 = value; }
}
[XmlElement(ElementName="Address3",IsNullable=false ,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Address3;
[XmlIgnore]
public string Address3
{
get { return __Address3; }
set { __Address3 = value; }
}
public T_ADDRESS()
{
}
}
[XmlType(TypeName="T_PERSONNAME"),Serializable]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public class T_PERSONNAME
{
[XmlElement(ElementName="Forename",IsNullable=false ,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Forename;
[XmlIgnore]
public string Forename
{
get { return __Forename; }
set { __Forename = value; }
}
[XmlElement(ElementName="Surname",IsNullable=false, DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Surname;
[XmlIgnore]
public string Surname
{
get { return __Surname; }
set { __Surname = value; }
}
[XmlElement(ElementName="MiddleName",IsNullable=fal se,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __MiddleName;
[XmlIgnore]
public string MiddleName
{
get { return __MiddleName; }
set { __MiddleName = value; }
}
public T_PERSONNAME()
{
}
}
[XmlRoot(ElementName="BaseTypes",Namespace=Declarat ions.SchemaVersion,IsNullable=false),Serializable]
public class BaseTypes
{
[XmlElement(Type=typeof(http___com_test_schemas_Bas eTypes.T_PERSONNAME),ElementName="PersonName",IsNu llable=false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public http___com_test_schemas_BaseTypes.T_PERSONNAME __PersonName;
[XmlIgnore]
public http___com_test_schemas_BaseTypes.T_PERSONNAME PersonName
{
get
{
if (__PersonName == null) __PersonName = new
http___com_test_schemas_BaseTypes.T_PERSONNAME();
return __PersonName;
}
set {__PersonName = value;}
}
[XmlElement(Type=typeof(http___com_test_schemas_Bas eTypes.T_ADDRESS),ElementName="AddressDetails",IsN ullable=false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public http___com_test_schemas_BaseTypes.T_ADDRESS __AddressDetails;
[XmlIgnore]
public http___com_test_schemas_BaseTypes.T_ADDRESS AddressDetails
{
get
{
if (__AddressDetails == null) __AddressDetails = new
http___com_test_schemas_BaseTypes.T_ADDRESS();
return __AddressDetails;
}
set {__AddressDetails = value;}
}
public BaseTypes()
{
}
}
}
// Copyright 2004, Microsoft Corporation
// Sample Code - Use restricted to terms of use defined in the accompanying
license agreement (EULA.doc)
//--------------------------------------------------------------
// Autogenerated by XSDObjectGen version 1.4.2.1
// Schema file: Person.xsd
// Creation Date: 21/03/2006 15:14:02
//--------------------------------------------------------------
using System;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
namespace http_com_test_schemas_Person
{
public struct Declarations
{
public const string SchemaVersion = "http://com.test.schemas.Person";
}
[XmlRoot(ElementName="Person",Namespace=Declaration s.SchemaVersion,IsNullable=false),Serializable]
public class Person
{
[XmlElement(ElementName="id",IsNullable=false,DataT ype="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __id;
[XmlIgnore]
public string id
{
get { return __id; }
set { __id = value; }
}
[XmlElement(Type=typeof(PersonName),ElementName="Pe rsonName",IsNullable=false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public PersonName __PersonName;
[XmlIgnore]
public PersonName PersonName
{
get
{
if (__PersonName == null) __PersonName = new PersonName();
return __PersonName;
}
set {__PersonName = value;}
}
public Person()
{
}
}
[XmlType(TypeName="PersonName"),Serializable]
public class PersonName : http___com_test_schemas_BaseTypes.T_PERSONNAME
{
[XmlElement(Type=typeof(FathersName),ElementName="F athersName",IsNullable=false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public FathersName __FathersName;
[XmlIgnore]
public FathersName FathersName
{
get
{
if (__FathersName == null) __FathersName = new FathersName();
return __FathersName;
}
set {__FathersName = value;}
}
[XmlElement(ElementName="Alias",IsNullable=false,Da taType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Alias;
[XmlIgnore]
public string Alias
{
get { return __Alias; }
set { __Alias = value; }
}
public PersonName() : base()
{
}
}
[XmlType(TypeName="FathersName"),Serializable]
public class FathersName
{
[XmlElement(ElementName="Forename",IsNullable=false ,DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Forename;
[XmlIgnore]
public string Forename
{
get { return __Forename; }
set { __Forename = value; }
}
[XmlElement(ElementName="Surname",IsNullable=false, DataType="string")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public string __Surname;
[XmlIgnore]
public string Surname
{
get { return __Surname; }
set { __Surname = value; }
}
public FathersName()
{
}
}
}
My problem is that when I actually browse the web service I do not see any
evidence of the PersonName base type which is inherited in Person.cs the line
in the class is
[XmlType(TypeName="PersonName"),Serializable]
public class PersonName : http___com_test_schemas_BaseTypes.T_PERSONNAME
The browser output is
TestInheritance
Test
The test form is only available for methods with primitive types or arrays
of primitive types as parameters.
SOAP
The following is a sample SOAP request and response. The placeholders shown
need to be replaced with actual values.
POST /XMLInheritanceSample/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/TestInheritance"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestInheritance xmlns="http://tempuri.org/">
<Person xmlns="http://com.test.schemas.Person">
<id>string</id>
<PersonName>
<FathersName>
<Forename>string</Forename>
<Surname>string</Surname>
</FathersName>
<Alias>string</Alias>
</PersonName>
</Person>
</TestInheritance>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestInheritanceResponse xmlns="http://tempuri.org/">
<TestInheritanceResult>string</TestInheritanceResult>
</TestInheritanceResponse>
</soap:Body>
</soap:Envelope>
Is there a reason for this?
BTW I can see the T_PERSONNAME defined in the service descripton.
Thanks in advance.