views:

96

answers:

1

Please help me with this one, I'm not sure what the correct, or best approach is. Basically I have a webservice which takes a byte stream, enabling a c# winform application to upload files to the webservice.

What I need is for the winform to upload in the background one file at a time (using basic multithread, it tries to upload them all at once). I also need to drop in there a progress bar.

How should I do it? Any ideas? I have the feeling it should be fairly straight forward. I think the application should start a new thread for the first file, wait until it's finished then dispose of the thread, create a new one for the next file and so on.

A: 

It completely depends on the technology you are using on the client side to access the web service.

If that technology allows for customization of the client proxy to the point where you can intercept transmission of messages (WCF allows this, I can't recall how much the old web services reference does), then you should be able to add your hook to see when the bytes are processed/sent.


Based on bookstorecowboy's comment about using the old "web reference" functionality in .NET, I believe that it generated proxies that derive from the SoapHttpClientProtocol class.

This being the case, I would recommend creating a custom class that derives from the SoapHttpClientProtocol class, overriding the GetWriterForMessage method. In this, you are supposed to return an XmlWriter given the Stream that is passed as a property on the SoapClientMessage parameter.

You would also create a custom class that derives from Stream which takes a Stream instance and forwards all the calls to that instance.

The only difference is that in the Write methods, you would fire an event indicating how many bytes were written.

You would then get the Stream that is exposed on the SoapClientMessage passed to the GetWriterForMessage and wrap it in your custom Stream implementation. You would also connect your event handlers here as well.

With that stream, you would create the XmlWriter and return it.

Then, for your proxies, you would use this new class that derives from SoapHttpClientProtocol and have the proxies derive from that.

casperOne
Thanks Casper, okay, so it's using the old fashioned .NET proxy version, and calling a webservice from there in c#, using a WINFORM. It creates a version of the webservice and then sends through the files. Some of the files are 20mb or so in length.
bookstorecowboy
Additionally it's sending an unknown number of files up, because it's basically backing up a user created directory, so it first scans the directory then pings up each file in turn.
bookstorecowboy