webservice upload and progress - winforms

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

Related

Can NReco PDF Generator somehow fire the event Session_End on an ASP.Net MVC Application?

I'm using NReco html-to-pdf converter to deliver a file stream representing a PDF document through an action method. However it seems that when I invoke the method HtmlToPdfConverter.GeneratePdf although the response is delivered correctly the session is abandoned right after. I know that because the event handler Session_End gets executed on the global.asax.
This premature non-explicit expiration of the session makes the application to misbehave in further requests that query the session object (now set to null)
That does not happen when I generate the PDF files with another third-party library: i. e. the pdf file is generated and served and the session keeps its state until it expires normally after some idle time.
Can NReco PDF Generator somehow fire the event Session_End on an ASP.Net MVC Application?
I know it would be easier to use the pdf library that does not show that behavior however it does not support some feature that Nreco does like CSS and javascript :S
Regards and thanks for your help

How do I do bi-directional communications using "Codename One New-Java-Javascript-Interop-API" in my specific use-case?

I have an App that makes intensive use of "browserComponent" and bidirectional communication between Java native code and Javascript embedded inside web-page content.
Now we must make the same thing using the New Async-Java-Javascript-Interop-API recently posted by Codename One.
In this context, We need to bind all buttons present on each page to routines coded in native code (java/kotlin) as soon the page is loaded.
How can we capture "Html Body on-load-event" and how to activate all binds that we need?
And, on the opposite direction, the java code that was triggered by html-buttons mentioned before, interacts with the users. As a result of these interactions, normally it is necessary to modify some values of javascript variables (frequently a javascript-array) and that way allowing update dynamically the document model in the Browser.
Any help on this subject will be very appreciated.
You can bind an onLoad event in the same way you always could using:
browserComponent.addWebEventListener(BrowserComponent.onLoad, e -> {
// here you can start writing JS binding code
});
For reference this article covers everything else about the binding https://www.codenameone.com/blog/new-async-java-javascript-interop-api.html

Enhancing my WCF service with asynchronous calls?

I am currently developing a WCF service in a windows form application. There would be a simple GUI screen with 2 buttons, "Start" and "Stop". Whenever I attempt to start the service, the UI of the application would temporary hangs until it loads finish. Is it possible to add a loading effect to it? And how can I do that.
Still pretty new in this area. Would welcome any comments!
Is there any good tutorials out there that teaches how can I enhance this issue?
I have read the MSDN blog tutorial from Rick Rainey Making asynchronous service calls from a WinForm client but it is not really that of a good tutorial.
Just to clarify, my WCF service is a publish subscribe framework and I think I do not need to be able to call the operations asynchronously. All I want to know is how do I initiate the connection asynchronously.
Is it possible to add a loading effect to it? And how can I do that.
For this you can use duplex service contract.
Also, since your application is a subscription application you might want to look into pushing data to your application from the WCF service. Here's a nice example and although it's for Silverlight I think it might be useful to you:
http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx

Unity to return new instance of service

I have come across a bit of a problem while using Unity and WPF. The scenario is I have a WPF application which follows the MVVM design pattern. A have a module called ViewKDI. Within this module I have a service called ViewKDIService, the ViewKDIService service utilises another service called UserService.
Every time I load the module ViewKDI I want Unity to return me a new instance of both the ViewKDIService and the UserService.
I have put the below in the shell bootstrapper:
Container.RegisterType<IUserService, UserService>();
In the ViewKDI module I have put the following:
Container.RegisterType<IViewKDIService, ViewKDIService>();
Each time the ViewKDI module loads the ViewKDIService constructor is called. However the UserService constructor is only called the first time, this means that I am not getting a new instance of UserService.
I require unity to give me a new instance of UserService too so that I can manage this session separately from the rest of the application.
Any ideas?
Thanks
Faisal
Unity's default behaviour is to create a new instance of each object each time one is requested, so you shouldn't be seeing this behaviour.
From what I can gather from the source code and MSDN documentation (this is a good read), you can specify a "lifetime manager" object when you register a type to tell Unity how the type should be constructed and cached. Using the TransientLifetimeManager (which essentially does no caching) will cause Unity to re-create the class each time. So try this:
Container.RegisterType<IUserService, UserService>(new TransientLifetimeManager());
... and see if it creates a new UserService each time.

mvc programming question

Am using a view file,controller and a helper. am accessing data value through webserver.
Steps:
the controller get value from webserver and set it in the view. the view uses the helper to display the data in some format. But my helper again calls the webserver method to get the inner values. Is it correct the helper accessing webservice method? Is it the correct way of programming in mvc?
Thanks,
IMO, a webservice is just another datasource and should be accessed via the model. If it's me, I handle it by either creating a new model for the service call (if the service call is in support of an existing entity, it may make more sense to make the call in that entity's model itself). My controller calls the model method, sends the data to my view which, in turn, forwards that data on to the helper.
This maintains the MVC separation, but still allows the data you need to make it's way into the helper where you need it.
I will tell you what is written in the Ruby on Rails book. I can not remember the title right now but...
Helpers are usually used for view rendering not for server calls.
Hope it helps.

Resources