Like the title says, I’m curious to know what state is contained in a WCF client proxy object – should I be new’ing up tons of these casually and not caring? Or are they more heavyweight and I shouldn’t be so cavalier about creating them?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not much really – the link to the communication channel, it’s state – that’s about it. WCF tends to be very much stateless, so both your client and the server won’t really hang on to a lot of state.
The cost of client-side proxy generation is two-part:
first, there’s a
ChannelFactory<T>that needs to be created (whereTis your service contract, e.g.IMyService). This part is fairly heavyweight, so if you can, cache the channel factorysecond, the channel factory is used to create the actual channel – this is quite a simple operation, and you shouldn’t bother to cache this.
If you’ve used the
Add Service Referencefunctionality in Visual Studio, orsvcutil.exeon the command line, you usually end up with a(YourService)Clientclass – this basically encapsulates those two steps for you.If you feel the urge to optimize, check out this two-step process and see if you can make it work for you, and if caching the factory (and thus limiting the number of factory instantiations) makes a difference for you.