try { using (MyProxy proxy = new MyProxy()) { proxy.SomeOperation(); } } catch (Exception ex) { ..... }If the call to the service operation results in 'faulting' the channel, the original exception will be lost because leaving the using block will trigger a call to the Close method on the proxy, resulting in another exception (telling you that the channel is faulted) which masks the original exception. The annoying thing is that the behaviour of this code is dependent on the type of binding used (e.g. with a basicHttpBinding everything goes well, with a wsHttpBinding the real exception is masked when the channel is faulted). You can come up with different solutions for this problem. Some examples: - Keep the using statement and embed each call to an operation in it's own try..catch statement. - Replace the using statement with a try..finally construction, where you check the channel status in the finally clause. If the channel is faulted, you can call the Abort method instead of the Close method.
Monday, June 9, 2008
Using statement and the WCF proxy
When you implement the closing of a WCF proxy with the 'using' statement, be aware that in some conditions exceptions can be lost.
Example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment