开发者

webservice upload and progress

开发者 https://www.devze.com 2022-12-15 06:52 出处:网络
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 web

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.


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.


As for ASP.NET 2.0 web services ("Old web services ") you could add web services extension to alter and extend it's behavior . You could also add custom Http module . It allows you aceess up to the stream level .

see Soap Extensions,Http Modules

0

精彩评论

暂无评论...
验证码 换一张
取 消