473,467 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

WCF: Why is the client's IDisposeable implementation private?

Why is the IDisposeable implementation of WCF clients private?

I'm glad that you can still Dispose() by casting or with using ( .. ) { .. }
because IDisposable is indeed implemented but what was the design reasoning
to make Dispose() private?

Jon
May 21 '07 #1
13 1516
* Jon Davis wrote, On 21-5-2007 23:59:
Why is the IDisposeable implementation of WCF clients private?

I'm glad that you can still Dispose() by casting or with using ( .. ) { .. }
because IDisposable is indeed implemented but what was the design reasoning
to make Dispose() private?

Jon

This is usually done when there is a Close, End or Finish function,
which will call Dispose for you.

Jesse
May 21 '07 #2

"Jesse Houwing" <je***********@nospam-sogeti.nlwrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
>* Jon Davis wrote, On 21-5-2007 23:59:
>Why is the IDisposeable implementation of WCF clients private?

I'm glad that you can still Dispose() by casting or with using ( .. ) {
.. } because IDisposable is indeed implemented but what was the design
reasoning to make Dispose() private?

This is usually done when there is a Close, End or Finish function, which
will call Dispose for you.
I had thought the reverse, that Dispose() would perform closures, as with
using 'using' with Stream objects.

Jon
May 21 '07 #3
* Jon Davis wrote, On 22-5-2007 0:51:
"Jesse Houwing" <je***********@nospam-sogeti.nlwrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
>* Jon Davis wrote, On 21-5-2007 23:59:
>>Why is the IDisposeable implementation of WCF clients private?

I'm glad that you can still Dispose() by casting or with using ( .. ) {
.. } because IDisposable is indeed implemented but what was the design
reasoning to make Dispose() private?
This is usually done when there is a Close, End or Finish function, which
will call Dispose for you.

I had thought the reverse, that Dispose() would perform closures, as with
using 'using' with Stream objects.
Both functions dispose. They're implemented exactly the same, but Close
or FInish is a more logical name to close the underlying
stream/connection/transaction etc.

See the Close function of the Stream Class (used reflector to get to that):

public virtual void Close()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
Jesse Houwing
May 22 '07 #4
Please note that Dispose method is not private. IDisposable is implemented
explicitly. This requires you to call the method on the reference of the
exact interface type.

"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.netwrote in message
news:eU**************@TK2MSFTNGP03.phx.gbl...
Why is the IDisposeable implementation of WCF clients private?

I'm glad that you can still Dispose() by casting or with using ( .. ) {
.. } because IDisposable is indeed implemented but what was the design
reasoning to make Dispose() private?

Jon

May 22 '07 #5

"Jesse Houwing" <je***********@nospam-sogeti.nlwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>* Jon Davis wrote, On 22-5-2007 0:51:
>I had thought the reverse, that Dispose() would perform closures, as with
using 'using' with Stream objects.

Both functions dispose. They're implemented exactly the same, but Close or
FInish is a more logical name to close the underlying
stream/connection/transaction etc.

See the Close function of the Stream Class (used reflector to get to
that):

public virtual void Close()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
That may be true, but it isn't obvious, and I don't like the inconsistent
design. SqlConnection has a Close() method, too, but it does not dispose.
http://blog.devstone.com/aaron/archi...06/03/184.aspx This is useful
because you can reopen a closed object. Generally if I see Close() I expect
to be able to reopen it if I want to, but I'm finding that a WCF client is
completely useless once Close() is called--whatever unmanaged resources were
exposed won't be recreated for me, I have to create a whole new WCF client.
Which is annoying because I'm trying to work with an "abstractly configured"
WCF client interface.

Jon
May 23 '07 #6
I'm finding that a WCF client is completely useless once Close() is
called--whatever unmanaged resources were exposed won't be recreated for
me, I have to create a whole new WCF client. Which is annoying because I'm
trying to work with an "abstractly configured" WCF client interface.
Incidentally, what's the deal with Faulted state? I can't
((IDisposable)client).Dispose() because it's in a faulted state. I can't
Close() it because it's in a faulted state. And if I just let it drop out of
scope before I recreate a new client, everything hangs for three seconds!!!!

Jon
May 23 '07 #7
Seriously? It causes Dispose() to fail? Eek. Looking at reflector,
Dispose() simply calls Close(), so I would (as you state) expect them
to behave the same... but I do hate it when Dispose() throws... it
makes tidy cleanup a pain...

Marc
May 23 '07 #8

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Seriously? It causes Dispose() to fail? Eek. Looking at reflector,
Dispose() simply calls Close(), so I would (as you state) expect them to
behave the same... but I do hate it when Dispose() throws... it makes tidy
cleanup a pain...
Yeah, the server is throwing an exception, and passing back a fault. Seeing
that and then trying again on the client side, Close() and Dispose() both
raise exceptions, "because it is in a Faulted state". (And without
Close()ing it, it hangs for seconds when I create and call a new client.)

Finding this I went home last night red-faced mad and wondering if
Microsoft's WCF QA team consists of 12-year-old children. I know that can't
be the case, so I'd like to know the simple answer to this problem.

Jon
May 23 '07 #9
Finding this I went home last night red-faced mad and wondering if
Microsoft's WCF QA team consists of 12-year-old children. I know that
can't be the case, so I'd like to know the simple answer to this problem.
It seems calling Abort() instead of Close() when in Faulted state seems to
resolve the 3-second wait issue. Reflection says that Abort() raises the
OnClosing and OnClosed events. It seems the dependency objects are using
delegate hooks to this event (InputQueueChannel<TDisposable>,
LayeredChannel<TInnerChannel>, PeerChannelListenerBase,
PeerDuplexChannelAcceptor, PeerInputChannelAcceptor, PeerOutputChannel,
WrapperSecurityCommunicationObject) ... not sure if any of these are even in
use. I'm surprised that Reflection's Analyze feature supports finding uses
of this event.

Jon
May 23 '07 #10
Alright, so, in conclusion of a long-winded thread where I keep talking to
myself, I must say I am horrified by Microsoft's inconsistency.

IDisposable was always percieved to be the happy, safe haven for getting rid
of objects that use managed resources. If something implemented IDisposable,
Dispose() was always callable. Not so anymore.

((IDisposable)client).Dispose() can only be called on a WCF client if
Close() can be called, because internally it calls Close(). Close() cannot
be called unless basically it's in the Open state; otherwise, you have to
execute Abort() instead, which is not a memeber of IDisposable. This means
that, even though the object does indeed implement IDisposable, its
*SUPPORT* for IDisposable is 100% dependent upon the caller evaluating the
State of the object to determine whether or not it's open. In other words,
Microsoft has establish a new precedent: IDisposable mandates extraneous
state-checking code before its IDisposable implementation is usable, and the
only thing you can do about it is wrap it. I might've opted to create a new
interface, IReallyDispose, but then I'd still have to implement it. I could
create an abstract class, WcfDisposable, but C# doesn't support multiple
inheritance. The best I can do is put a sticky note on my computer monitor
that reads: "WCF client objects don't REALLY implement IDisposable unless
they're Open!" Then I can only hope that I'll pay attention to my stickynote
when I'm going about WCF coding.

Does anyone else besides me find this to be unacceptably stupid and messy? I
really *WANT* to like WCF. I love greenfield projects that use promising new
technology, but when new technology abandons key design patterns like this,
it really gets under my skin.

Jon
May 23 '07 #11
Alright, so, in conclusion of a long-winded thread where I keep talking to
myself, I must say I am horrified by Microsoft's inconsistency.

IDisposable was always percieved to be the happy, safe haven for getting rid
of objects that use unmanaged resources. If something implemented
IDisposable, Dispose() was always callable. Not so anymore.

((IDisposable)client).Dispose() can only be called on a WCF client if
Close() can be called, because internally it calls Close(). Close() cannot
be called unless basically it's in the Open state; otherwise, you have to
execute Abort() instead, which is not a memeber of IDisposable. This means
that, even though the object does indeed implement IDisposable, its
*SUPPORT* for IDisposable is 100% dependent upon the caller evaluating the
State of the object to determine whether or not it's open. In other words,
Microsoft has establish a new precedent: IDisposable mandates extraneous
state-checking code before its IDisposable implementation is usable, and the
only thing you can do about it is wrap it. I might've opted to create a new
interface, IReallyDispose, but then I'd still have to implement it. I could
create an abstract class, WcfDisposable, but C# doesn't support multiple
inheritance. The best I can do is put a sticky note on my computer monitor
that reads: "WCF client objects don't REALLY implement IDisposable unless
they're Open!" Then I can only hope that I'll pay attention to my stickynote
when I'm going about WCF coding.

Does anyone else besides me find this to be unacceptably stupid and messy? I
really *WANT* to like WCF. I love greenfield projects that use promising new
technology, but when new technology abandons key design patterns like this,
it really gets under my skin.

Jon

May 23 '07 #12
Jon Davis skrev:
Alright, so, in conclusion of a long-winded thread where I keep talking to
myself, I must say I am horrified by Microsoft's inconsistency.
You've only just scratched the surface yet, and there's som *ugly* old
paint down there related to finalizers which shines through as
Dispose(bool).

Finalization is not ordered wrt. referencing (think about it, how would
you finalize a cyclic chain if it was -- but it's not even ordered for
non-cyclic reference chains).

Because of that, a class with a finalizer (and methods invoked by it)
cannot (safely) use the objects its object references, since they may
already have been finalized.

Many System.* classes (for example Stream) implement IDisposable
"solving" this using the "Dispose(bool)" pattern
(http://msdn2.microsoft.com/en-us/lib...s2xkftw.aspx):

class Foo: IDisposable {
IDisposable.Dispose() {
Dispose(true);
}
protected void Dispose(bool disposing) {
if ( disposing )
// dispose managed resources
// dispose unmanaged resources
}
~Foo() { Dispose(false); }
}

Even more unnerving is the way that object finalization elegibility is
interpreted. Since the finalizer runs on a separate thread an object may
be finalized while a method is still being invoked on it! See
http://msdn2.microsoft.com/en-us/lib...keepalive.aspx.

The "fix" is to GC.KeepAlive(o), but compilers are allowed to optimize
that away in situations where it can prove that GC.KeepAlive is never
run (making the refernce to o dead), for example in:

Foo o = new Foo();
return o.f(); // o may be finalized while o.f is still running
GC.KeepAlive(o);

so to fix *that* you need to write your code in a way that prevents the
compiler from proving that GC.KeepAlive runs, for example:

public static volatile bool fool_the_compiler = true;

Foo o = new Foo();
if ( fool_the_compiler )
return o.f();
GC.KeepAlive(o);
throw new InvalidOperationException(); // must return or throw :)

Happy hacking :)

.....

Well, fortunatly it's not a problem very often in the real world. but it
stinks just the same.

--
Helge
May 23 '07 #13
Sorry for the multi-post; all does not appear well in NNTP-land ;-p

Marc

May 23 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jtbjurstrom | last post by:
Bear with me because we are new to WCF and have been going through documentation and samples trying to absorb as much as possible in a short amount of time. Any suggestions would be much...
0
by: =?Utf-8?B?QWRyaWFuIENvbGU=?= | last post by:
I have written a simple WCF service hosted in a Windows console application and a simple WCF client console application that connects successfully to that service and retrieves data. I then ported...
3
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have just created a WCF service that is using WShttpbasic and all is good when another .net 3.0 application consumes it. However, I have legacy apps that must use this service and are running on...
0
by: =?Utf-8?B?UmljaGFyZCBDb2xsZXR0ZQ==?= | last post by:
My goal is to connect a WSE 3.0 client to a WCF asp.net hosted service, utilizing MTOM encoding and if at all possible, streamedRequest transfer mode. I am starting with a basic Hello World...
4
by: Dave Burns | last post by:
Hello, I am trying to specify a logical default value for a in a WCF Web Service using basicHttpBinding. I realize that the language defaults are: int - 0 string - null bool - false
16
by: =?Utf-8?B?U3RldmUgQmFya2Vy?= | last post by:
WCF Question Hi guys, I’m pretty new to WCF, and have a basic question about how it works. I’m trying to use WCF to write an “SOA-system”, and am having a few problems. The...
5
by: =?Utf-8?B?TWFyaw==?= | last post by:
I'm researching what is the best way to create a generic WCF proxy wrapper that has the following requirements: 1. Remove the System.ServiceModel config section requirement for clients. We have...
2
by: =?Utf-8?B?RWRkaWU=?= | last post by:
Here is my scenario for a problem I can't solve. I am hosting a 3.5 WCF service in IIS on Windows Server 2003. The service works fine with the WCF test client in Visual Studio 2008 and from an...
3
by: cmrhema | last post by:
Hi, Kindly excuse if I am posting in the wrong place. I am using Visual Studio 2008, .net framework 3.5, asp.net , c# and sql server 2005. I am supposed to pass stored procedures from client...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.