XML Validation problem

Discussion in 'ASP .Net Web Services' started by John S, Mar 3, 2009.

  1. John S

    John S Guest

    I have a web servicce which receives an XMLDocument and then uses the
    XMLDocument.Validate method to make sure it is valid.

    I'm then using a ValidationEventHandler to pick up any failures.

    I need to be able to store those failures in some way so that they can be
    returned to the calling process.

    I tried using an arraylist but VB tells me it has to be shred for the
    eventhandler and the other methods in the web service to all access the data.

    However, making it shared means that any other calls coming in at the same
    time will also access and write to it. Deffinitely not what I need!

    Can anyone tell me how to do this correctly?

    Thanks
    John S, Mar 3, 2009
    #1
    1. Advertising

  2. John S

    John S Guest

    That sounds like what I'm trying to do.

    However, I'm using VB and although I tried to convert your example I didn't
    have much luck.

    Can you help?

    Thanks

    "John S" wrote:

    > I have a web servicce which receives an XMLDocument and then uses the
    > XMLDocument.Validate method to make sure it is valid.
    >
    > I'm then using a ValidationEventHandler to pick up any failures.
    >
    > I need to be able to store those failures in some way so that they can be
    > returned to the calling process.
    >
    > I tried using an arraylist but VB tells me it has to be shred for the
    > eventhandler and the other methods in the web service to all access the data.
    >
    > However, making it shared means that any other calls coming in at the same
    > time will also access and write to it. Deffinitely not what I need!
    >
    > Can anyone tell me how to do this correctly?
    >
    > Thanks
    >
    >
    John S, Mar 4, 2009
    #2
    1. Advertising

  3. John S

    Steven Cheng Guest

    Thanks for your quick reply John,

    No problem. Here is the VB.NET version of my test code snippet:


    =======helper class===========
    Public Class MyValidationHelper

    Public Messages As New System.Collections.Generic.List(Of String)

    Public Sub ValidationHandler(ByVal sender As Object, ByVal e As
    System.Xml.Schema.ValidationEventArgs)

    Messages.Add(e.Message)

    End Sub

    End Class
    =====================


    ======use helper class in web method =======
    <WebMethod()> _
    Public Function TestWebMethod(ByVal doc As System.Xml.XmlDocument) As
    String

    Dim vhelper As New MyValidationHelper()
    'validatethe xml first
    doc.Validate(AddressOf vhelper.ValidationHandler)

    Return "Validation Result, error count: " & vhelper.Messages.Count

    End Function
    End Class
    ==================

    If there is anything else unclear, please feel free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.


    --------------------

    >From: =?Utf-8?B?Sm9obiBT?= <>
    >References: <>
    >Subject: RE: XML Validation problem
    >Date: Wed, 4 Mar 2009 00:26:01 -0800


    >
    >That sounds like what I'm trying to do.
    >
    >However, I'm using VB and although I tried to convert your example I

    didn't
    >have much luck.
    >
    >Can you help?
    >
    >Thanks
    >
    >"John S" wrote:
    >
    >> I have a web servicce which receives an XMLDocument and then uses the
    >> XMLDocument.Validate method to make sure it is valid.
    >>
    >> I'm then using a ValidationEventHandler to pick up any failures.
    >>
    >> I need to be able to store those failures in some way so that they can

    be
    >> returned to the calling process.
    >>
    >> I tried using an arraylist but VB tells me it has to be shred for the
    >> eventhandler and the other methods in the web service to all access the

    data.
    >>
    >> However, making it shared means that any other calls coming in at the

    same
    >> time will also access and write to it. Deffinitely not what I need!
    >>
    >> Can anyone tell me how to do this correctly?
    >>
    >> Thanks
    >>
    >>

    >
    Steven Cheng, Mar 4, 2009
    #3
  4. John S

    John S Guest

    That did the job.

    Many thanks

    ""Steven Cheng"" wrote:

    > Thanks for your quick reply John,
    >
    > No problem. Here is the VB.NET version of my test code snippet:
    >
    >
    > =======helper class===========
    > Public Class MyValidationHelper
    >
    > Public Messages As New System.Collections.Generic.List(Of String)
    >
    > Public Sub ValidationHandler(ByVal sender As Object, ByVal e As
    > System.Xml.Schema.ValidationEventArgs)
    >
    > Messages.Add(e.Message)
    >
    > End Sub
    >
    > End Class
    > =====================
    >
    >
    > ======use helper class in web method =======
    > <WebMethod()> _
    > Public Function TestWebMethod(ByVal doc As System.Xml.XmlDocument) As
    > String
    >
    > Dim vhelper As New MyValidationHelper()
    > 'validatethe xml first
    > doc.Validate(AddressOf vhelper.ValidationHandler)
    >
    > Return "Validation Result, error count: " & vhelper.Messages.Count
    >
    > End Function
    > End Class
    > ==================
    >
    > If there is anything else unclear, please feel free to post here.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    >
    >
    > --------------------
    >
    > >From: =?Utf-8?B?Sm9obiBT?= <>
    > >References: <>
    > >Subject: RE: XML Validation problem
    > >Date: Wed, 4 Mar 2009 00:26:01 -0800

    >
    > >
    > >That sounds like what I'm trying to do.
    > >
    > >However, I'm using VB and although I tried to convert your example I

    > didn't
    > >have much luck.
    > >
    > >Can you help?
    > >
    > >Thanks
    > >
    > >"John S" wrote:
    > >
    > >> I have a web servicce which receives an XMLDocument and then uses the
    > >> XMLDocument.Validate method to make sure it is valid.
    > >>
    > >> I'm then using a ValidationEventHandler to pick up any failures.
    > >>
    > >> I need to be able to store those failures in some way so that they can

    > be
    > >> returned to the calling process.
    > >>
    > >> I tried using an arraylist but VB tells me it has to be shred for the
    > >> eventhandler and the other methods in the web service to all access the

    > data.
    > >>
    > >> However, making it shared means that any other calls coming in at the

    > same
    > >> time will also access and write to it. Deffinitely not what I need!
    > >>
    > >> Can anyone tell me how to do this correctly?
    > >>
    > >> Thanks
    > >>
    > >>

    > >

    >
    >
    John S, Mar 5, 2009
    #4
  5. John S

    Steven Cheng Guest

    You're welcome:)

    Have a nice day!

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .
    Steven Cheng, Mar 6, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page