Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / May 2008

Tip: Looking for answers? Try searching our database.

Validate Xml from Serialized Web Service Proxy Class throws on soap Array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joris van Lier - 23 May 2008 15:41 GMT
Hi, im trying to validate objects before they are sent over the wire to a
webservice,
the schema embedded into WSDL is not sufficient so i took that schema and
extended it with additional restrictions,
after conversion from local domain class into remote domain class the remote
class (generated from WSDL) is serialized to XML and validated using the
schema, this throws "Undefined complexType
http://schemas.xmlsoap.org/soap/encoding/:Array is used as restriction of
complex type" (translated)

How do i add this schema or map the soap array to another type?

       private void ValidateRemoteDomainObject(remote.webservice.entity o)
       {
           MemoryStream ms = new MemoryStream();
           XmlSerializer xs = new XmlSerializer(o.GetType());
           xs.Serialize(ms, o);
           ms.Position = 0;
           ValidateXmlSchema(new StreamReader(ms), "Schema.xsd");
       }

       void ValidateXmlSchema(TextReader reader, string schemaUri)
       {
           XmlReaderSettings xrs = new XmlReaderSettings();
           xrs.ValidationType = ValidationType.Schema;
           xrs.ValidationFlags &=
~XmlSchemaValidationFlags.AllowXmlAttributes;
           xrs.ValidationFlags |=
XmlSchemaValidationFlags.ReportValidationWarnings;
           xrs.ValidationEventHandler += new
ValidationEventHandler(ValidationEventHandler);
           XmlSchema schema = XmlSchema.Read(
               XmlReader.Create(schemaUri), this.ValidationEventHandler);
           xrs.Schemas.Add(schema);
           XmlReader xr = XmlReader.Create(reader, xrs);
           while(xr.Read()){
               // do something with node
           }
       }

       void ValidationEventHandler(object sender, ValidationEventArgs e)
       {
           throw new ApplicationException(
               String.Format("{0}", new object[] {e.Message}),
               e.Exception
           );
       }

Joris van Lier
Martin Honnen - 23 May 2008 16:19 GMT
> Hi, im trying to validate objects before they are sent over the wire to
> a webservice,
[quoted text clipped - 5 lines]
> http://schemas.xmlsoap.org/soap/encoding/:Array is used as restriction
> of complex type" (translated)

You need a schema for the namespace
http://schemas.xmlsoap.org/soap/encoding/ that defines the Array type. I
am not sure whether the various soap specifications define a schema,
perhaps someone in microsoft.public.dotnet.framework.aspnet.webservices
knows more.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.