RE: Asynchronous Web Service Method Failure

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Turbo (Turbo_at_discussions.microsoft.com)
Date: 12/17/04


Date: Thu, 16 Dec 2004 16:31:03 -0800

Let's say I have a web service called wsReportGenerator that has a method
called CreateReport. This method will create a .pdf or XML spread*** and
return the URL of the file created.

Class wsReportGenerator
Inherits System.Web.Services.WebService
<WebMethod()> Public Function CreateReport() as String

    create report logic is here and the file (either .pdf or XML
spread***) is
    is saved to the hard drive somewhere on the server.

    return "\ReportFolder\ReportName.pdf" ' virtual location of report

End Function
End Class

So, when I call this method where appropriate, it's

dim ws as new wsReportGenerator()
 or using the proxy from a web reference, ProxyReportGenerator()
dim URL as string = wsReportGenerator.CreateReport()
Response.Redirect(URL, True)

Because the CreateReport method can take a while to run, I call it
asynchronously using a proxy so it looks more like

dim ws as new ProxyReportGenerator()
ws.BeginCreateReport(callback, ws)

Obviously I need to check to see if it's finished every now and then so in
my callback procedure I have
dim URL as string = ws.EndCreateReport(iAsyncResult)
I save the URL in a session variable so the next time I check, it's there
and I can redirect.

When I call a method that opens stream readers or writers somewhere within,
I have no problem running them using the first way, which is synchronous.
They fail when I use the Proxy/Begin method, which invokes the method
asynchronously. Methods that don't open streams run either way with no
problem.

I appreciate you taking the time to look at this. I'm having trouble
explaining it. When I say async in this case, I mean using the
Proxy.BeginMethodName where Proxy would be derived from
System.Web.Services.Protocols.SoapHttpClientProtocol, the class generated
from setting a web reference to a service.

"Dan Rogers" wrote:

> I'm still confused about what you mean by async. How are you invoking them
> a) when it works, and b) when it doesn't work. Since you are returning
> values to the caller, I am pretty sure that these are not async server side
> operations, but you are referring to the non-blocking (beginMethodXX) on
> the caller side as "async".
>
> is this the case? If so, there is no difference in the way the call is
> dispatched and handled on the server side - so again, my confusion as to
> why the stream reader thinks the thread is async.
>
> Something in the description here (topology - e.g. what code are you trying
> to invoke on what side of a web service method call) is eluding me.
>
> Dan
> --------------------
> >Thread-Topic: Asynchronous Web Service Method Failure
> >thread-index: AcTi3k4zag4FdGNeSzOsg9ucQ1yLug==
> >X-WBNR-Posting-Host: 65.118.1.233
> >From: "=?Utf-8?B?VHVyYm8=?=" <Turbo@discussions.microsoft.com>
> >References: <4F6A0DC8-92A1-4BB9-9E07-43123A799944@microsoft.com>
> <00lXKSV4EHA.3388@cpmsftngxa10.phx.gbl>
> >Subject: RE: Asynchronous Web Service Method Failure
> >Date: Wed, 15 Dec 2004 11:43:09 -0800
> >Lines: 77
> >Message-ID: <E3D1275E-5CE8-4DCE-8145-0BAA1A0BE8EB@microsoft.com>
> >MIME-Version: 1.0
> >Content-Type: text/plain;
> > charset="Utf-8"
> >Content-Transfer-Encoding: 7bit
> >X-Newsreader: Microsoft CDO for Windows 2000
> >Content-Class: urn:content-classes:message
> >Importance: normal
> >Priority: normal
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
> >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> >Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> >Xref: cpmsftngxa10.phx.gbl
> microsoft.public.dotnet.framework.aspnet.webservices:27228
> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
> >
> >Here is the procedure. I call an asynchronous web service method for a
> >particular report. I don't pass any files, just parameters for the
> report,
> >such as start date and end date. The web service methods don't return any
> >files, just URL's to the files so I can execute a response.redirect when
> the
> >web service is done creating the report. Some of my reports are XML
> >spreadsheets, so to avoid have to create the XML from scratch, I use
> existing
> >files and then add the necessary data elements to them. Within the web
> >service method that is creating the report, I open a streamreader or use
> the
> >XMLDocument Load method in order to get the static XML loaded into the
> >XMLDocument. When I'm done, I use a streamwriter to create an
> XmlTextWriter
> >to save the document. These methods work fine when done synchronously,
> but
> >fail when done async. Only methods that use objects derived from
> >streamreaders and writers fail when run async. I hope I'm making myself
> >clear. The error message box that pops up only occurs during development.
>
> >It isn't a client issue.
> >
> >"Dan Rogers" wrote:
> >
> >> Some questions,
> >>
> >> When you say async - do you mean you have created a one-way SOAP method?
>
> >> (this is the right way to think about async for web services). When you
> >> have a one-way method, you don't get to write a response. In other
> words,
> >> async server side methods have a "void" signature always. If you try
> >> marking a non-void method with the one way soap attribute, that is an
> error.
> >>
> >> That aside, you should consider using SOAP with attachments if you are
> >> returning files (no longe async methods).
> >>
> >> I hope this helps
> >>
> >> Dan Rogers
> >> Microsoft Corporation
> >> --------------------
> >> >Thread-Topic: Asynchronous Web Service Method Failure
> >> >thread-index: AcTe/QkQd8iqbozvTCKTbAiYn3Wy0A==
> >> >X-WBNR-Posting-Host: 65.118.1.233
> >> >From: "=?Utf-8?B?VHVyYm8=?=" <Turbo@discussions.microsoft.com>
> >> >Subject: Asynchronous Web Service Method Failure
> >> >Date: Fri, 10 Dec 2004 13:13:03 -0800
> >> >Lines: 12
> >> >Message-ID: <4F6A0DC8-92A1-4BB9-9E07-43123A799944@microsoft.com>
> >> >MIME-Version: 1.0
> >> >Content-Type: text/plain;
> >> > charset="Utf-8"
> >> >Content-Transfer-Encoding: 7bit
> >> >X-Newsreader: Microsoft CDO for Windows 2000
> >> >Content-Class: urn:content-classes:message
> >> >Importance: normal
> >> >Priority: normal
> >> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> >> >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
> >> >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> >> >Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> >> >Xref: cpmsftngxa10.phx.gbl
> >> microsoft.public.dotnet.framework.aspnet.webservices:27146
> >> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
> >> >
> >> >Greetings to all
> >> >
> >> >I have a set of web services that create reports upon request. These
> >> >reports can take the form of XML Spreadsheets or dynamically generated
> >> .pdf
> >> >files. I call the create report methods async to give the user the
> >> >opportunity to cancel a long running report. However, any create
> report
> >> >method that opens a stream reader (in order to import some XML for a
> >> >spread***) or writer (in order to generate the XML spread*** file)
> >> cannot
> >> >be run async. They run fine synchronously, but for some reason,
> opening
> >> an
> >> >IO.Stream causes a "there was an error during async processing" error.
> >> The
> >> >interesting thing is, this error is given in a message box, not a
> typical
> >> >ASP.NET error page. Any thoughts?
> >> >
> >>
> >>
> >
>
>


Quantcast