Skip to main content
Home Forums Silverlight Programming Accessing Web Services with Silverlight Hook into WCF proxy's generic begin and end operation
7 replies. Latest Post by Michel Metselaar on November 16, 2009.
(0)
Michel M...
Member
55 points
48 Posts
11-07-2009 12:20 PM |
I am developing a Silverlight app that communicates with a WCF service using a generated proxy (add service reference).
The proxy operations are being called from many places in the application source. I need to show a progress bar during each request, but I want to do this in a generic way. It would be nice if I can hook into generic 'BeginInvoke' and 'EndInvoke' operations of the proxy, so there is only one place in my code where I manage the state of the progress bar.
Is it possible?
Thanks in advance.
esite
Participant
1448 points
310 Posts
11-10-2009 3:39 AM |
I guess you could write generic class that inherits from System.ServiceModel.ClientBase but it would mean that you will need to change your inheritance everytime you generate your proxy.
A better way would probably be to rather write a base class on your client side that can do this function and gets called whenever you make a request and receive a response.
11-10-2009 4:22 AM |
Thanks for your answer.
The generated ClientBase class is partial. It would be nice if it is possible to hook into some events instead of overriding each method.I am looking for a central place to put the progress bar handling in.
11-10-2009 5:06 AM |
I see the only events on the ClientBase is for Opening and Closing, which in effect could do the same thing for you since your calls will open and close for each request.
http://msdn.microsoft.com/en-us/library/ms576143.aspx
11-10-2009 6:00 AM |
I tried your suggestion.
I created an event handler for the Open event of the ClientBase's InnerChannel. That works.But my event handler for the Close event of the ClientBase's InnerChannel doesn't get called. That is probably because I don't close the proxy. I think I have to close the proxy when the response is returned. I have to look for documentation what is the best way to close the proxy in an asynchronous scenario.
11-10-2009 12:16 PM |
From my understanding the best way to close it and always close it should, is the same as when you browse to you .SVC file in IE thus
myClient.CloseAsync();
Right after your call as it will only close when the Async calls returns, there the CloseAsync
11-10-2009 12:43 PM |
Thanks again. The use of the close method in asynchronous communication was always a mystery to me. Calling the close method is missing in most samples on the internet.
11-16-2009 12:15 PM |
I received useful information:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/5546f5c2-55b4-4110-9c5e-4a234660e8b1/?prof=required