tags:

views:

192

answers:

0

Hi, I try used custom XML serialization on my own class with IXmlSerializable, and also use xml scheme.

public class Service : System.Web.Services.WebService
{
    [XmlSchemaProvider("GetSchemaDocument")]
    public class EmployeeDetails3 : IXmlSerializable
    {

        public int employeeID;

        public string firstName;

        public string lastName;

        private string phoneNumber;

        const string ns = "";

        public static XmlQualifiedName GetSchemaDocument(XmlSchemaSet xs)
        {

            string schemaPath =
             "E:\\Project\\CustomSerializationInASPNET.WebService\\App_Data\\EmployeeDetails3.xsd";

            XmlSerializer schemaSerializer = new XmlSerializer(typeof(XmlSchema));
            XmlSchema s = (XmlSchema)schemaSerializer.Deserialize(new XmlTextReader(schemaPath), null);
            xs.XmlResolver = new XmlUrlResolver();
            xs.Add(s);
            return new XmlQualifiedName("EmployeeDetails3", ns);
        }

        void IXmlSerializable.WriteXml(XmlWriter w)
        {

            w.WriteStartElement("Employee", ns);

            w.WriteStartElement("Name", ns);

            w.WriteElementString("First", ns, firstName);

            w.WriteElementString("Last", ns, lastName);

            w.WriteEndElement();

            w.WriteElementString("ID", ns, employeeID.ToString());

            w.WriteElementString("Phone", ns, phoneNumber.ToString());

            w.WriteEndElement();

        }


        System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
        {

            return null;

        }

        public EmployeeDetails3()
        { }

        public EmployeeDetails3(int employeeID, string firstName, string lastName, string phoneNumber)
        {

            this.employeeID = employeeID;

            this.firstName = firstName;

            this.lastName = lastName;

            this.phoneNumber = phoneNumber;
        }

    }


    [WebMethod]
    public EmployeeDetails3[] GetEmployee3()
    {
        EmployeeDetails3[] employeeObj = new EmployeeDetails3[3];

        employeeObj[0] = new EmployeeDetails3(1, "X", "X", "X");
        employeeObj[1] = new EmployeeDetails3(2, "Y", "Y", "Y");
        employeeObj[2] = new EmployeeDetails3(3, "Z", "Z", "Z");

        return employeeObj;
    }
}

Xml scheme for my own object is :

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="EmployeeDetails" nillable="true" type="EmployeeDetails" />
  <xs:complexType name="EmployeeDetails">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="First" type="xs:string" />
      <xs:element minOccurs="0" maxOccurs="1" name="Last" type="xs:string" />
      <xs:element minOccurs="1" maxOccurs="1" name="ID" type="xs:int" />
      <xs:element minOccurs="0" maxOccurs="1" name="Phone" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

I think the xml scheme is wrong, I am beginner. What is wrong with my xml scheme ?

If I try compile my project and test on asp.net development server it finish with this warnning:

T*his web service does not conform to WS-I Basic Profile v1.1.

Please examine each of the normative statement violations below. Follow the recommendations to remedy it, or add setting to the config section to turn off BP 1.1 conformance warnings for the entire vroot.

To turn off BP 1.1 conformance warnings for the entire vroot remove the 'BP1.1' value from the section of the configuration file of your application:

R2105: All xsd:schema elements contained in a wsdl:types element of a DESCRIPTION MUST have a targetNamespace attribute with a valid and non-null value, UNLESS the xsd:schema element has xsd:import and/or xsd:annotation as its only child element(s). - schema from service description with targetNamespace='http://tempuri.org/'.

Recommendation: Please examine your schema definitions and add explicit targetNamespace attribute. Requiring a targetNamespace on all xsd:schema elements that are children of wsdl:types is a good practice, places a minimal burden on authors of WSDL documents, and avoids the cases that are not as clearly defined as they might be.*