views:

17

answers:

1

Hi all I have a webservice with a webmethod that accepts an XML from a client via POST (don't know if this really matters), validates XML and the data inside, and then processes the XML and returns an answer to the client.

At moment, I have a problem with large XMLs; it takes too long for the XML preprocessing to finish, and the clients timeout expires.

Instead of increasing the timeout of the client I thought I could maybe separate the XML validation from the XML processing by starting a new thread after the validation which processes the XML and at the same time return the validation answer to the client. (the processing won't start if the XML is not valid.

Now my question is: Will opening the new thread increase memory usage? normally I would guess it will (for normal applications) but here I am returning an answer to the client and essentially ending the process of the main thread.

And another question, I actually tried to create a small webservice that does just that but for some reason, even though the webmethod was finished, the client would not get an answer back until the thread died... am I doing something wrong?

Ok, I rewrote the small webservice and it actully works (I haven't tried it on the real code yet - it's a tad more complicated).
This is the example code if anyone wants it:

Imports System.Web.Services
Imports System.Web.Services.Protocols    
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService()> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class DemoService
    Inherits System.Web.Services.WebService

       <WebMethod()> _
    Public Function XMLReceiver(ByVal XMLData As String) As Integer
        Dim retval As Integer = Validate(XMLData)
        Dim thrd As New Threading.Thread(AddressOf Process)
        thrd.Start()
        Return retval
    End Function

    Public Function Validate(ByVal XMLData As String) As Integer
        Return 0
    End Function

    Public Sub Process()
        'get time
        Dim start As Date = Date.Now
        'do work
        Threading.Thread.Sleep(1000 * 10)
        'notification (actually write to DB)
        Dim writer As New IO.StreamWriter("C:\done.txt")
        writer.WriteLine("From " & start.ToLongTimeString & " To " & Date.Now.ToLongTimeString & " done!")
        writer.Close()
    End Sub
End Class

So Now it's just a matter of the first question.

Thanks everyone

A: 

I don't think you need to change the XML process logic, but how your client calls it. You should be calling the webservice asynchronously. So you would provide a callback method that would be called when the webservice has completed its work. Now without seeing the code it is hard to propose any real answer, but I think based on what you have written so far this may be the issue.

Wade73
I added the code above. I don't want to use asynchronic calls. After I verify the XML I can retrieve an answer - that is the only thing the client cares about and I don't want to keep him hanging for a second call, because he has nothing else to do until I give him a result. The processing doesn't concern the client.
Doody P
after reading your comment again and posting the demo code, it seems I don't have anywhere that I call Thread.Join(). Does this matter? Thanks!
Doody P
I unfortunately not much help in that case, sorry.
Wade73