473,770 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WCF Client Proxy and caching...

I'm researching what is the best way to create a generic WCF proxy wrapper
that has the following requirements:

1. Remove the System.ServiceM odel config section requirement for clients. We
have our own configuration management that follows our application lifecycle
(development/system test/production). Also, most of the proxies we build are
for the middle-tier layer.

2. Create a wrapper to follow WCF Client best practices (proxy.close &
exception handling). My thought was to use the "Using" statement for
resource cleanup. (But I found another article that states otherwise :
http://msdn.microsoft.com/en-us/library/ms733912.aspx)

3. In some scenarios, adjust binding security as required by an
application/service.

4. In most scenarios, we do not want to expose MEX/WSDL of the service, with
the exception of Development.

I have found numerous articles that discuss this particular topic. Based on
my knowledge of WCF, there are two ways for a client to call a WCF service...

1. Add a Service Reference.
2. Dynamically build the proxy based on the WSDL.

Basically, that leaves option 1 (due to requirement #4). With that said, I
found two different approaches of calling WCF services…

1. Use the ClientBase<TCha nnel>
2. Use the ChannelFactory< TChannel>

After researching the topic, I’m leaning toward option 2 and found numerous
samples on the Internet. However, I do have a question about what to cache
for performance. Most articles said to cache the proxy and reuse it as much
as possible. But, according to some articles I found, if you have to change
the binding, for example, you shouldn’t cache (Create, call, and close the
connection). Is this referring to the proxy created after calling
CreateChannel on the ChannelFactory class?
Any guidance would be most appreciated.

Thanks

--
Mark Remkiewicz
Systems Architect
Sep 24 '08 #1
5 5471
Mark,

When using ChannelBase, you're in fact calling:
- ChannelFactory. Create
- factory.CreateC hannel
- ... use channel ...
- channel.Close
- factory.Close

ChannelFactory has the advantage of providing channel pooling, similar to
the known ADO connection pooling, although not exactly the same. When using
ChannelFactory, you tipically instantiate the factory once, and afterwards
keep it alive (in a static, for example), and keep on creating channels from
it. When creating the factory, you're required to provide all authentication
data required, which means that you may not change authentication elements
on channel creation.

When used in a middle tier scenario, and if the client credentials to
present downstream depend on the upstream credentials then you should also
distinguish the factories cached statically using, for example, a
dictionary. You would not want to be using a channel (with credentials
already set by its factory) that did not reflect the original upstream
credentials ...

Another thing to remember, when you close the channel, the channel goes back
to the channel pool of the factory, differently from ClientBase, where the
factory and channel are both destroyed.

avoid using the "using" keyword, since on closure (imagine an exception
occured and Dispose is called) you'll sometimes get a msg sent back and
since you already got an error on the channel and its now unusable, you're
left with an immediate exception of communication failure and you lose the
original exception. I'd avise the following channel usage:

channel c = factory createchannel()
try
{ c.method();
}
finally
{
try { c.close(); } catch { c.abort(); }
}

Finally, regarding a possible class to manage channel creation, destruction,
exception, see:
http://groups.google.com/group/micro...8167ad3dd3a4e8

hope it helps
Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:9A******** *************** ***********@mic rosoft.com...
I'm researching what is the best way to create a generic WCF proxy wrapper
that has the following requirements:

1. Remove the System.ServiceM odel config section requirement for clients.
We
have our own configuration management that follows our application
lifecycle
(development/system test/production). Also, most of the proxies we build
are
for the middle-tier layer.

2. Create a wrapper to follow WCF Client best practices (proxy.close &
exception handling). My thought was to use the "Using" statement for
resource cleanup. (But I found another article that states otherwise :
http://msdn.microsoft.com/en-us/library/ms733912.aspx)

3. In some scenarios, adjust binding security as required by an
application/service.

4. In most scenarios, we do not want to expose MEX/WSDL of the service,
with
the exception of Development.

I have found numerous articles that discuss this particular topic. Based
on
my knowledge of WCF, there are two ways for a client to call a WCF
service...

1. Add a Service Reference.
2. Dynamically build the proxy based on the WSDL.

Basically, that leaves option 1 (due to requirement #4). With that said,
I
found two different approaches of calling WCF services…

1. Use the ClientBase<TCha nnel>
2. Use the ChannelFactory< TChannel>

After researching the topic, I’m leaning toward option 2 and found
numerous
samples on the Internet. However, I do have a question about what to
cache
for performance. Most articles said to cache the proxy and reuse it as
much
as possible. But, according to some articles I found, if you have to
change
the binding, for example, you shouldn’t cache (Create, call, and close the
connection). Is this referring to the proxy created after calling
CreateChannel on the ChannelFactory class?
Any guidance would be most appreciated.

Thanks

--
Mark Remkiewicz
Systems Architect
Sep 28 '08 #2
Thanks for the reply.

Just to clarify, I should cache the factory created by CreateFactory(O f T).
If I need to pass credentials downstream, I should create a cache for each
factory based on the credentials (which makes sense).

Concerning the using statement... I wanted to create a pattern for our
developers to use. Here is a sample (This is not complete because I wanted
to have a strategy on caching the proxy):

Public MustInherit Class WcfWebServicePr oxy(Of TProxy As
{WCF.ClientBase (Of TChannel), New}, TChannel As Class)
Implements IDisposable

Protected Sub New()

End Sub

Private mProxy As TChannel = Nothing

Public Sub Close()

Dim channel As WCF.ICommunicat ionObject = TryCast(mProxy,
WCF.ICommunicat ionObject)

Try
If channel IsNot Nothing Then
If channel.State <WCF.Communicat ionState.Faulte d Then
channel.Close()
Else
channel.Abort()
End If
End If

Catch ex As WCF.Communicati onException
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As TimeoutExceptio n
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As Exception
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Throw
End Try

End Sub

#Region " IDisposable Support "

Private mDisposedValue As Boolean = False ' To detect
redundant calls

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not mDisposedValue Then
If disposing Then
Try
Close()
Catch
'Catch all - The error is logged
End Try
End If
End If
mDisposedValue = True
End Sub

' This code added by Visual Basic to correctly implement the
disposable pattern.
Public Sub Dispose() Implements IDisposable.Dis pose
' Do not change this code. Put cleanup code in Dispose(ByVal
disposing As Boolean) above.
Dispose(True)
GC.SuppressFina lize(Me)
End Sub

#End Region

End Class

This sample was based on an article I found that I thought came close to
what you were referring to about handling the close and exception handling.
Your thoughts?

--
Mark Remkiewicz
Systems Architect
"Tiago Halm" wrote:
Mark,

When using ChannelBase, you're in fact calling:
- ChannelFactory. Create
- factory.CreateC hannel
- ... use channel ...
- channel.Close
- factory.Close

ChannelFactory has the advantage of providing channel pooling, similar to
the known ADO connection pooling, although not exactly the same. When using
ChannelFactory, you tipically instantiate the factory once, and afterwards
keep it alive (in a static, for example), and keep on creating channels from
it. When creating the factory, you're required to provide all authentication
data required, which means that you may not change authentication elements
on channel creation.

When used in a middle tier scenario, and if the client credentials to
present downstream depend on the upstream credentials then you should also
distinguish the factories cached statically using, for example, a
dictionary. You would not want to be using a channel (with credentials
already set by its factory) that did not reflect the original upstream
credentials ...

Another thing to remember, when you close the channel, the channel goes back
to the channel pool of the factory, differently from ClientBase, where the
factory and channel are both destroyed.

avoid using the "using" keyword, since on closure (imagine an exception
occured and Dispose is called) you'll sometimes get a msg sent back and
since you already got an error on the channel and its now unusable, you're
left with an immediate exception of communication failure and you lose the
original exception. I'd avise the following channel usage:

channel c = factory createchannel()
try
{ c.method();
}
finally
{
try { c.close(); } catch { c.abort(); }
}

Finally, regarding a possible class to manage channel creation, destruction,
exception, see:
http://groups.google.com/group/micro...8167ad3dd3a4e8

hope it helps
Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:9A******** *************** ***********@mic rosoft.com...
I'm researching what is the best way to create a generic WCF proxy wrapper
that has the following requirements:

1. Remove the System.ServiceM odel config section requirement for clients.
We
have our own configuration management that follows our application
lifecycle
(development/system test/production). Also, most of the proxies we build
are
for the middle-tier layer.

2. Create a wrapper to follow WCF Client best practices (proxy.close &
exception handling). My thought was to use the "Using" statement for
resource cleanup. (But I found another article that states otherwise :
http://msdn.microsoft.com/en-us/library/ms733912.aspx)

3. In some scenarios, adjust binding security as required by an
application/service.

4. In most scenarios, we do not want to expose MEX/WSDL of the service,
with
the exception of Development.

I have found numerous articles that discuss this particular topic. Based
on
my knowledge of WCF, there are two ways for a client to call a WCF
service...

1. Add a Service Reference.
2. Dynamically build the proxy based on the WSDL.

Basically, that leaves option 1 (due to requirement #4). With that said,
I
found two different approaches of calling WCF services…

1. Use the ClientBase<TCha nnel>
2. Use the ChannelFactory< TChannel>

After researching the topic, I’m leaning toward option 2 and found
numerous
samples on the Internet. However, I do have a question about what to
cache
for performance. Most articles said to cache the proxy and reuse it as
much
as possible. But, according to some articles I found, if you have to
change
the binding, for example, you shouldn’t cache (Create, call, and close the
connection). Is this referring to the proxy created after calling
CreateChannel on the ChannelFactory class?
Any guidance would be most appreciated.

Thanks

--
Mark Remkiewicz
Systems Architect
Sep 29 '08 #3
The class you're writing below looks similar to the class here:
http://forums.microsoft.com/MSDN/Sho...15745&SiteID=1

You're still missing the factory caching, though. The IDisposable
implementation is so the developers use the "using" statement? You then need
IDisposable to behave the same has Close (besides surpressing finalize as
you're doing).

But, doesn't it look a bit misleading to the developer? Careful so the
developer does not end up using the "using" keyword directly with a channel
and bypasses your class altogether. Its always good to let developers know
what they are dealing with and how it works.

Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:CA******** *************** ***********@mic rosoft.com...
Thanks for the reply.

Just to clarify, I should cache the factory created by CreateFactory(O f
T).
If I need to pass credentials downstream, I should create a cache for each
factory based on the credentials (which makes sense).

Concerning the using statement... I wanted to create a pattern for our
developers to use. Here is a sample (This is not complete because I
wanted
to have a strategy on caching the proxy):

Public MustInherit Class WcfWebServicePr oxy(Of TProxy As
{WCF.ClientBase (Of TChannel), New}, TChannel As Class)
Implements IDisposable

Protected Sub New()

End Sub

Private mProxy As TChannel = Nothing

Public Sub Close()

Dim channel As WCF.ICommunicat ionObject = TryCast(mProxy,
WCF.ICommunicat ionObject)

Try
If channel IsNot Nothing Then
If channel.State <WCF.Communicat ionState.Faulte d Then
channel.Close()
Else
channel.Abort()
End If
End If

Catch ex As WCF.Communicati onException
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As TimeoutExceptio n
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As Exception
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Throw
End Try

End Sub

#Region " IDisposable Support "

Private mDisposedValue As Boolean = False ' To detect
redundant calls

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not mDisposedValue Then
If disposing Then
Try
Close()
Catch
'Catch all - The error is logged
End Try
End If
End If
mDisposedValue = True
End Sub

' This code added by Visual Basic to correctly implement the
disposable pattern.
Public Sub Dispose() Implements IDisposable.Dis pose
' Do not change this code. Put cleanup code in Dispose(ByVal
disposing As Boolean) above.
Dispose(True)
GC.SuppressFina lize(Me)
End Sub

#End Region

End Class

This sample was based on an article I found that I thought came close to
what you were referring to about handling the close and exception
handling.
Your thoughts?

--
Mark Remkiewicz
Systems Architect
"Tiago Halm" wrote:
>Mark,

When using ChannelBase, you're in fact calling:
- ChannelFactory. Create
- factory.CreateC hannel
- ... use channel ...
- channel.Close
- factory.Close

ChannelFacto ry has the advantage of providing channel pooling, similar to
the known ADO connection pooling, although not exactly the same. When
using
ChannelFactory , you tipically instantiate the factory once, and
afterwards
keep it alive (in a static, for example), and keep on creating channels
from
it. When creating the factory, you're required to provide all
authenticati on
data required, which means that you may not change authentication
elements
on channel creation.

When used in a middle tier scenario, and if the client credentials to
present downstream depend on the upstream credentials then you should
also
distinguish the factories cached statically using, for example, a
dictionary. You would not want to be using a channel (with credentials
already set by its factory) that did not reflect the original upstream
credentials ...

Another thing to remember, when you close the channel, the channel goes
back
to the channel pool of the factory, differently from ClientBase, where
the
factory and channel are both destroyed.

avoid using the "using" keyword, since on closure (imagine an exception
occured and Dispose is called) you'll sometimes get a msg sent back and
since you already got an error on the channel and its now unusable,
you're
left with an immediate exception of communication failure and you lose
the
original exception. I'd avise the following channel usage:

channel c = factory createchannel()
try
{ c.method();
}
finally
{
try { c.close(); } catch { c.abort(); }
}

Finally, regarding a possible class to manage channel creation,
destruction,
exception, see:
http://groups.google.com/group/micro...8167ad3dd3a4e8

hope it helps
Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:9A******* *************** ************@mi crosoft.com...
I'm researching what is the best way to create a generic WCF proxy
wrapper
that has the following requirements:

1. Remove the System.ServiceM odel config section requirement for
clients.
We
have our own configuration management that follows our application
lifecycle
(development/system test/production). Also, most of the proxies we
build
are
for the middle-tier layer.

2. Create a wrapper to follow WCF Client best practices (proxy.close &
exception handling). My thought was to use the "Using" statement for
resource cleanup. (But I found another article that states otherwise :
http://msdn.microsoft.com/en-us/library/ms733912.aspx)

3. In some scenarios, adjust binding security as required by an
application/service.

4. In most scenarios, we do not want to expose MEX/WSDL of the service,
with
the exception of Development.

I have found numerous articles that discuss this particular topic.
Based
on
my knowledge of WCF, there are two ways for a client to call a WCF
service...

1. Add a Service Reference.
2. Dynamically build the proxy based on the WSDL.

Basically, that leaves option 1 (due to requirement #4). With that
said,
I
found two different approaches of calling WCF services…

1. Use the ClientBase<TCha nnel>
2. Use the ChannelFactory< TChannel>

After researching the topic, I’m leaning toward option 2 and found
numerous
samples on the Internet. However, I do have a question about what to
cache
for performance. Most articles said to cache the proxy and reuse it as
much
as possible. But, according to some articles I found, if you have to
change
the binding, for example, you shouldn’t cache (Create, call, and close
the
connection). Is this referring to the proxy created after calling
CreateChannel on the ChannelFactory class?
Any guidance would be most appreciated.

Thanks

--
Mark Remkiewicz
Systems Architect
Sep 29 '08 #4
Yes, the sample is not complete, because I wanted to know what to cache.
This is why you are not seeing the factory cache.

If you look at "Protected Overridable Sub Dispose(ByVal disposing As
Boolean)", I call the close method. I wrap the close in this method to trap
all errors here, so exceptions are not thrown.
But, doesn't it look a bit misleading to the developer? Careful so the
developer does not end up using the "using" keyword directly with a channel
and bypasses your class altogether. Its always good to let developers know
what they are dealing with and how it works.
I'm not following the above statement. This is a base class for the
developers to inherit to create proxy wrappers, so they don't need to write
all this logic.

One other question... Your sample included a factory.close call. I don't
see that on object created from the ChannelFactory( Of T). Is there another
interface I must look at?

--
Mark Remkiewicz
Systems Architect
"Tiago Halm" wrote:
The class you're writing below looks similar to the class here:
http://forums.microsoft.com/MSDN/Sho...15745&SiteID=1

You're still missing the factory caching, though. The IDisposable
implementation is so the developers use the "using" statement? You then need
IDisposable to behave the same has Close (besides surpressing finalize as
you're doing).

But, doesn't it look a bit misleading to the developer? Careful so the
developer does not end up using the "using" keyword directly with a channel
and bypasses your class altogether. Its always good to let developers know
what they are dealing with and how it works.

Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:CA******** *************** ***********@mic rosoft.com...
Thanks for the reply.

Just to clarify, I should cache the factory created by CreateFactory(O f
T).
If I need to pass credentials downstream, I should create a cache for each
factory based on the credentials (which makes sense).

Concerning the using statement... I wanted to create a pattern for our
developers to use. Here is a sample (This is not complete because I
wanted
to have a strategy on caching the proxy):

Public MustInherit Class WcfWebServicePr oxy(Of TProxy As
{WCF.ClientBase (Of TChannel), New}, TChannel As Class)
Implements IDisposable

Protected Sub New()

End Sub

Private mProxy As TChannel = Nothing

Public Sub Close()

Dim channel As WCF.ICommunicat ionObject = TryCast(mProxy,
WCF.ICommunicat ionObject)

Try
If channel IsNot Nothing Then
If channel.State <WCF.Communicat ionState.Faulte d Then
channel.Close()
Else
channel.Abort()
End If
End If

Catch ex As WCF.Communicati onException
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As TimeoutExceptio n
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As Exception
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Throw
End Try

End Sub

#Region " IDisposable Support "

Private mDisposedValue As Boolean = False ' To detect
redundant calls

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not mDisposedValue Then
If disposing Then
Try
Close()
Catch
'Catch all - The error is logged
End Try
End If
End If
mDisposedValue = True
End Sub

' This code added by Visual Basic to correctly implement the
disposable pattern.
Public Sub Dispose() Implements IDisposable.Dis pose
' Do not change this code. Put cleanup code in Dispose(ByVal
disposing As Boolean) above.
Dispose(True)
GC.SuppressFina lize(Me)
End Sub

#End Region

End Class

This sample was based on an article I found that I thought came close to
what you were referring to about handling the close and exception
handling.
Your thoughts?

--
Mark Remkiewicz
Systems Architect
"Tiago Halm" wrote:
Mark,

When using ChannelBase, you're in fact calling:
- ChannelFactory. Create
- factory.CreateC hannel
- ... use channel ...
- channel.Close
- factory.Close

ChannelFactory has the advantage of providing channel pooling, similar to
the known ADO connection pooling, although not exactly the same. When
using
ChannelFactory, you tipically instantiate the factory once, and
afterwards
keep it alive (in a static, for example), and keep on creating channels
from
it. When creating the factory, you're required to provide all
authentication
data required, which means that you may not change authentication
elements
on channel creation.

When used in a middle tier scenario, and if the client credentials to
present downstream depend on the upstream credentials then you should
also
distinguish the factories cached statically using, for example, a
dictionary. You would not want to be using a channel (with credentials
already set by its factory) that did not reflect the original upstream
credentials ...

Another thing to remember, when you close the channel, the channel goes
back
to the channel pool of the factory, differently from ClientBase, where
the
factory and channel are both destroyed.

avoid using the "using" keyword, since on closure (imagine an exception
occured and Dispose is called) you'll sometimes get a msg sent back and
since you already got an error on the channel and its now unusable,
you're
left with an immediate exception of communication failure and you lose
the
original exception. I'd avise the following channel usage:

channel c = factory createchannel()
try
{ c.method();
}
finally
{
try { c.close(); } catch { c.abort(); }
}

Finally, regarding a possible class to manage channel creation,
destruction,
exception, see:
http://groups.google.com/group/micro...8167ad3dd3a4e8

hope it helps
Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:9A******** *************** ***********@mic rosoft.com...
I'm researching what is the best way to create a generic WCF proxy
wrapper
that has the following requirements:

1. Remove the System.ServiceM odel config section requirement for
clients.
We
have our own configuration management that follows our application
lifecycle
(development/system test/production). Also, most of the proxies we
build
are
for the middle-tier layer.

2. Create a wrapper to follow WCF Client best practices (proxy.close &
exception handling). My thought was to use the "Using" statement for
resource cleanup. (But I found another article that states otherwise :
http://msdn.microsoft.com/en-us/library/ms733912.aspx)

3. In some scenarios, adjust binding security as required by an
application/service.

4. In most scenarios, we do not want to expose MEX/WSDL of the service,
with
the exception of Development.

I have found numerous articles that discuss this particular topic.
Based
on
my knowledge of WCF, there are two ways for a client to call a WCF
service...

1. Add a Service Reference.
2. Dynamically build the proxy based on the WSDL.

Basically, that leaves option 1 (due to requirement #4). With that
said,
I
found two different approaches of calling WCF services…

1. Use the ClientBase<TCha nnel>
2. Use the ChannelFactory< TChannel>

After researching the topic, I’m leaning toward option 2 and found
numerous
samples on the Internet. However, I do have a question about what to
cache
for performance. Most articles said to cache the proxy and reuse it as
much
as possible. But, according to some articles I found, if you have to
change
the binding, for example, you shouldn’t cache (Create, call, and close
the
connection). Is this referring to the proxy created after calling
CreateChannel on the ChannelFactory class?
Any guidance would be most appreciated.

Thanks

--
Mark Remkiewicz
Systems Architect
Sep 29 '08 #5
Hi Mark,
>But, doesn't it look a bit misleading to the developer? Careful so the
developer does not end up using the "using" keyword directly with a
channel
and bypasses your class altogether. Its always good to let developers
know
what they are dealing with and how it works.
I'm not following the above statement. This is a base class for the
developers to inherit to create proxy wrappers, so they don't need to
write
all this logic.
I was just emphasizing the fact that it would be useful to let developers
know, nevertheless, that using the "using" keyword with a raw channel is not
a good idea, although it is expected to be used with your channel wrapper.
One other question... Your sample included a factory.close call. I don't
see that on object created from the ChannelFactory( Of T). Is there
another
interface I must look at?
My pseudo code with "factory.cl ose" was meant to show you what a ChannelBase
usage does. ChannelBase underneath does a factory creation, then a channel
creation, the call itself, finally a channel close and a factory close when
you close it.

The sample included in this link is in fact a wrapper for channels and makes
effetive usage of ChannelFactory. It should be easy to adapt it to your
needs - I'd see your wrapper using this class underneath for channel
management. I did use it for something similar to what you're doing.
http://forums.microsoft.com/MSDN/Sho...15745&SiteID=1

Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:72******** *************** ***********@mic rosoft.com...
Yes, the sample is not complete, because I wanted to know what to cache.
This is why you are not seeing the factory cache.

If you look at "Protected Overridable Sub Dispose(ByVal disposing As
Boolean)", I call the close method. I wrap the close in this method to
trap
all errors here, so exceptions are not thrown.
>But, doesn't it look a bit misleading to the developer? Careful so the
developer does not end up using the "using" keyword directly with a
channel
and bypasses your class altogether. Its always good to let developers
know
what they are dealing with and how it works.

I'm not following the above statement. This is a base class for the
developers to inherit to create proxy wrappers, so they don't need to
write
all this logic.

One other question... Your sample included a factory.close call. I don't
see that on object created from the ChannelFactory( Of T). Is there
another
interface I must look at?

--
Mark Remkiewicz
Systems Architect
"Tiago Halm" wrote:
>The class you're writing below looks similar to the class here:
http://forums.microsoft.com/MSDN/Sho...15745&SiteID=1

You're still missing the factory caching, though. The IDisposable
implementati on is so the developers use the "using" statement? You then
need
IDisposable to behave the same has Close (besides surpressing finalize as
you're doing).

But, doesn't it look a bit misleading to the developer? Careful so the
developer does not end up using the "using" keyword directly with a
channel
and bypasses your class altogether. Its always good to let developers
know
what they are dealing with and how it works.

Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:CA******* *************** ************@mi crosoft.com...
Thanks for the reply.

Just to clarify, I should cache the factory created by CreateFactory(O f
T).
If I need to pass credentials downstream, I should create a cache for
each
factory based on the credentials (which makes sense).

Concerning the using statement... I wanted to create a pattern for our
developers to use. Here is a sample (This is not complete because I
wanted
to have a strategy on caching the proxy):

Public MustInherit Class WcfWebServicePr oxy(Of TProxy As
{WCF.ClientBase (Of TChannel), New}, TChannel As Class)
Implements IDisposable

Protected Sub New()

End Sub

Private mProxy As TChannel = Nothing

Public Sub Close()

Dim channel As WCF.ICommunicat ionObject = TryCast(mProxy,
WCF.ICommunicat ionObject)

Try
If channel IsNot Nothing Then
If channel.State <WCF.Communicat ionState.Faulte d
Then
channel.Close()
Else
channel.Abort()
End If
End If

Catch ex As WCF.Communicati onException
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As TimeoutExceptio n
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Catch ex As Exception
channel.Abort()
ExceptionPublis her.CallPublish ExceptionWebSer vice(ex)
Throw
End Try

End Sub

#Region " IDisposable Support "

Private mDisposedValue As Boolean = False ' To detect
redundant calls

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not mDisposedValue Then
If disposing Then
Try
Close()
Catch
'Catch all - The error is logged
End Try
End If
End If
mDisposedValue = True
End Sub

' This code added by Visual Basic to correctly implement the
disposable pattern.
Public Sub Dispose() Implements IDisposable.Dis pose
' Do not change this code. Put cleanup code in
Dispose(ByVal
disposing As Boolean) above.
Dispose(True)
GC.SuppressFina lize(Me)
End Sub

#End Region

End Class

This sample was based on an article I found that I thought came close
to
what you were referring to about handling the close and exception
handling.
Your thoughts?

--
Mark Remkiewicz
Systems Architect
"Tiago Halm" wrote:

Mark,

When using ChannelBase, you're in fact calling:
- ChannelFactory. Create
- factory.CreateC hannel
- ... use channel ...
- channel.Close
- factory.Close

ChannelFacto ry has the advantage of providing channel pooling, similar
to
the known ADO connection pooling, although not exactly the same. When
using
ChannelFactory , you tipically instantiate the factory once, and
afterwards
keep it alive (in a static, for example), and keep on creating
channels
from
it. When creating the factory, you're required to provide all
authenticati on
data required, which means that you may not change authentication
elements
on channel creation.

When used in a middle tier scenario, and if the client credentials to
present downstream depend on the upstream credentials then you should
also
distinguish the factories cached statically using, for example, a
dictionary. You would not want to be using a channel (with credentials
already set by its factory) that did not reflect the original upstream
credentials ...

Another thing to remember, when you close the channel, the channel
goes
back
to the channel pool of the factory, differently from ClientBase, where
the
factory and channel are both destroyed.

avoid using the "using" keyword, since on closure (imagine an
exception
occured and Dispose is called) you'll sometimes get a msg sent back
and
since you already got an error on the channel and its now unusable,
you're
left with an immediate exception of communication failure and you lose
the
original exception. I'd avise the following channel usage:

channel c = factory createchannel()
try
{ c.method();
}
finally
{
try { c.close(); } catch { c.abort(); }
}

Finally, regarding a possible class to manage channel creation,
destruction,
exception, see:
http://groups.google.com/group/micro...8167ad3dd3a4e8

hope it helps
Tiago Halm

"Mark" <Ma**@discussio ns.microsoft.co mwrote in message
news:9A******* *************** ************@mi crosoft.com...
I'm researching what is the best way to create a generic WCF proxy
wrapper
that has the following requirements:

1. Remove the System.ServiceM odel config section requirement for
clients.
We
have our own configuration management that follows our application
lifecycle
(development/system test/production). Also, most of the proxies we
build
are
for the middle-tier layer.

2. Create a wrapper to follow WCF Client best practices (proxy.close
&
exception handling). My thought was to use the "Using" statement
for
resource cleanup. (But I found another article that states otherwise
:
http://msdn.microsoft.com/en-us/library/ms733912.aspx)

3. In some scenarios, adjust binding security as required by an
application/service.

4. In most scenarios, we do not want to expose MEX/WSDL of the
service,
with
the exception of Development.

I have found numerous articles that discuss this particular topic.
Based
on
my knowledge of WCF, there are two ways for a client to call a WCF
service...

1. Add a Service Reference.
2. Dynamically build the proxy based on the WSDL.

Basically, that leaves option 1 (due to requirement #4). With that
said,
I
found two different approaches of calling WCF services…

1. Use the ClientBase<TCha nnel>
2. Use the ChannelFactory< TChannel>

After researching the topic, I’m leaning toward option 2 and found
numerous
samples on the Internet. However, I do have a question about what
to
cache
for performance. Most articles said to cache the proxy and reuse it
as
much
as possible. But, according to some articles I found, if you have
to
change
the binding, for example, you shouldn’t cache (Create, call, and
close
the
connection). Is this referring to the proxy created after calling
CreateChannel on the ChannelFactory class?
Any guidance would be most appreciated.

Thanks

--
Mark Remkiewicz
Systems Architect
Sep 30 '08 #6

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

Similar topics

0
1178
by: Abhishek Srivastava | last post by:
Hello All, How do I completly and totally disable any kind of caching when making a HttpWebRequest. I have an application which downloads a file from the web. This file is updated on a daily basis. However, my application keeps downloading the same file again and again. When I open the same URL from my browser and hit the refresh button, I see the new version of the file.
3
2281
by: Søren Reinke | last post by:
Hi there For at project i need to build a Soap proxy with build in caching functionality. The reason is our backend system that we communicate with by Soap, does not always answer (break down, update and more) and some of the queries takes a LONG time (minutes) because the data is needed for our company website i want to cache some of the non changing data in a proxy/cahing program.
7
2928
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure out to create a "DataSet" as the return type from the webservice?
8
14091
by: A.M-SG | last post by:
Hi, I understand that we can install SOAP extensions through web.config at the server side. How do I install them at the client proxy side? Thank you, Alan
0
1086
by: John | last post by:
We want to prevent the caching in our project, so we have the following line of code in the page load function Response.AppendHeader("Cache-Control", "no-store"); But when we are using proxy server and IE, the page is cached to the local machine. But the page is not cached with firefox and proxy server.
1
15139
by: khubieb | last post by:
Situation: We have to connect to a 3rd party XML Web Service outside our LAN by adding a WCF Service Reference to a simple console application Problem: When attempting to invoke any of the generated client class methods, we recieve the following error: "The remote server returned an unexpected response: (407) Proxy Authentication Required ( The ISA
3
5992
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi, I have a winform client which consumes a WCF service. I have a single service client(proxy) at the winform side, but spread the service calls into multiple threads so that they can do works concurrently. My confusion is, as all threads share the same proxy, will one thread block another while calling a long running service? Is this related to the service concurrent configuration? Thanks.
2
1480
by: Doken13 | last post by:
I got an intranet web site and there is a proxy on the network. I want to retreive a client's IP, how could I get it ?
5
3075
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... I've got a .Net client to a soap service that works for the most part, but there are a couple of things I'd like to improve: 1) the first request to the client wrapper always takes 12-15 seconds even though the web server shows < a half second spent on the request. What takes so much time for the client wrapper to warm up? All subsequent requests, even to the same method, take the half second.
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6712
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.