Dispose
Unwanted Object Through WCF Service
1.
Open Our Project in Visual Studio.
2.
Go
to Solution Explorer and open Web Project
à WCF Service( Folder) à Sales ( Folder) à SalesClient.svc(Service) and then open
SalesClient.svc.cs file.
3. Add one file SilverlightFaultBehavior.cs
in our Web Project. This
file is an auto-generated file to
enable WCF Fault s to reach Silverlight Clients. Main
Use of SiverlightFaultBehavior.cs file
is to handling WCF Service Exceptions within Silverlight Application.
4.
Two
new attributes we have added SilverlightFaultBehavior and ServiceBehavior.
5.
SalesClient
is a service class.here we have implemented
an interface IDisposable.We have to use as implicitly.Namespace for
IDisposable is System.
After
Implement interface IDisposable one Dispose method will created at end.
then replace
that Dispose method code to above code
mention here:
In Above Code
Dispose ( ) method is use for implement IDisposable.here we called Garbage
Collector for dispose unwanted object. SuppresFinalize method should
only be called by a class that has a finalizer. It's informing the GC that this
object was cleaned up
fully. We can pass managed
private object references inside if(disposing) block .
6.
~SalesClient(
) is a finalizer. and it works as a destructor.
7.
Build
that Web and then update
Service References those are related to
SalesClient.svc. That Service Reference exists which is our Silverlight Project.
For Update
Service Reference Just Right Click on Service Reference and Click Update
Service reference.
Note:
We can use
same process for other server side layers if we want to disposed unwanted
objects.