Skip to main content

Microsoft Silverlight

Answered Question Hook into WCF proxy's generic begin and end operationRSS Feed

(0)

Michel Metselaar
Michel M...

Member

Member

55 points

48 Posts

Hook into WCF proxy's generic begin and end operation

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
esite

Participant

Participant

1448 points

310 Posts

Re: Hook into WCF proxy's generic begin and end operation

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.

Please mark replies as answers if they answered your question.

Anton Swanevelder
eSite Solutions

Michel Metselaar
Michel M...

Member

Member

55 points

48 Posts

Re: Hook into WCF proxy's generic begin and end operation

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.

esite
esite

Participant

Participant

1448 points

310 Posts

Answered Question

Re: Hook into WCF proxy's generic begin and end operation

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

Please mark replies as answers if they answered your question.

Anton Swanevelder
eSite Solutions

Michel Metselaar
Michel M...

Member

Member

55 points

48 Posts

Re: Hook into WCF proxy's generic begin and end operation

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.

esite
esite

Participant

Participant

1448 points

310 Posts

Answered Question

Re: Hook into WCF proxy's generic begin and end operation

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

Please mark replies as answers if they answered your question.

Anton Swanevelder
eSite Solutions

Michel Metselaar
Michel M...

Member

Member

55 points

48 Posts

Re: Hook into WCF proxy's generic begin and end operation

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.

Michel Metselaar
Michel M...

Member

Member

55 points

48 Posts

Answered Question

Re: Hook into WCF proxy's generic begin and end operation

I received useful information:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/5546f5c2-55b4-4110-9c5e-4a234660e8b1/?prof=required

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities