Hi,

I a real newbie on WCF, and I want to implement a service that reads from a DB some data and returns generic lists of custom objects to the client.

So I implement the service like this:
Interface:

<ServiceContract()> _
Public Interface IRepositorio

    <OperationContract(Name:="ListarAlmacen")> _
    Function ListarAlmacen() As List(Of BE.Almacen)

End Interface

Implementation:

<AspNetCompatibilityRequirementsAttribute(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
<ServiceBehavior(UseSynchronizationContext:=True, InstanceContextMode:=InstanceContextMode.PerSession, ConcurrencyMode:=ConcurrencyMode.Multiple)> _
Public Class Repositorio
    Implements IRepositorio

    Public Function ListarAlmacen() As List(Of BE.Almacen) Implements IRepositorio.ListarAlmacen
        Dim result As List(Of BE.Almacen)
        result = BL.Repositorio.Almacen.listar()
        Return result
    End Function

End Class

and on the client (a ASP.NET website, added the ServiceReference on the project),

'some code ...

            Dim oAlmacenWCF As New repositorio.RepositorioClient
            Dim oListaAlmacenBE As List(Of BE.Almacen)
            oListaItemAlmacenBE = oAlmacenWCF.ListarAlmacen(item_id)

'some code

So, my problem is that when I first call the ListarAlmacen method it works ok, but when I tried to call it a second time, it gave me a timeout exception, I tried to step into to debug it, the first time it works, the debug steps into it; but the second time, it didn't.

I just have no idea what's happening, I tried some tips, but no luck (service log, web.config hacks, etc.).

Please some can tell me where's is the problem or how can I know for sure where to look for the problem...

Thanks!

Dani AI

Generated

Good instincts, . Timeouts that appear only on the second call are very often a lifecycle issue, not a too-short timeout. If the WCF client proxy is not cleanly closed (or aborted when faulted), the channel can linger in a bad state and block later calls. Your fix (calling Close) is the right move. The recommended pattern is: close on success; on TimeoutException or CommunicationException, call Abort and handle/report. This prevents faulted channels from poisoning subsequent calls. (learn.microsoft.com)

A robust VB pattern you can drop in:

Dim client As New repositorio.RepositorioClient()
Try
    Dim lista = client.ListarAlmacen()
    client.Close() ' success -> clean shutdown
Catch ex As TimeoutException
    client.Abort() : Throw
Catch ex As CommunicationException
    client.Abort() : Throw
Catch
    client.Abort() : Throw
End Try

This mirrors the official guidance to avoid relying on Using/Dispose for WCF clients (since Close() can throw) and ensures resources are released deterministically. (learn.microsoft.com)

On ’s note about OperationTimeout: when you add a Service Reference, the proxy’s OperationTimeout is initialized from the binding’s sendTimeout. There is no separate operationTimeout setting in config. To raise the per-call limit via Web.config, increase sendTimeout on your client binding; ReceiveTimeout is not used by the client in request/reply and on the service it mainly controls session-idle time. (learn.microsoft.com)

If you make multiple calls in one request, consider reusing a single RepositorioClient instance (open once, close once) and still follow the same close/abort rules. It reduces overhead and avoids stray channels. (learn.microsoft.com)

Recommended Answers

All 4 Replies

Set the timeout properties of WCF application to increase the default timeout. This can be done on the client side programmically or with a client side App.Config or a Web.config.

You can configure the OperationTimeout property for Proxy in the WCF client code.

For example

DirectCast(service, IContextChannel).OperationTimeout = New TimeSpan(0, 0, 240)

Refer: http://www.codeproject.com/KB/WCF/WCF_Operation_Timeout_.aspx

Hi Ramesh,

Thank you very much for the answer, I've been looking how to do it in the web.config (i have a website client, and I want to do it in the web.config), but have no luck...

This is my first try ... and I'm not quit sure if I have the concepts right.

My proxy is generated with the vs2008 with the option "Add Service Reference..."

My client web.config has:

<system.serviceModel>
    <bindings>
 <wsHttpBinding>
           <binding name="WSHttpBinding_IRepositorio" closeTimeout="00:01:00"
             openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
             bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
             textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
             <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
             <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
             <security mode="Message">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                   realm="" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true"
                   algorithmSuite="Default" establishSecurityContext="true" />
             </security>
          </binding>
       </wsHttpBinding>
    </bindings>
      <client>
<endpoint address="http://localhost:7604/Repositorio.svc" binding="wsHttpBinding"
    bindingConfiguration="WSHttpBinding_IRepositorio" contract="repositorio.IRepositorio"
    name="WSHttpBinding_IRepositorio">
    <identity>
     <dns value="localhost" />
    </identity>
   </endpoint>
      </client>
	</system.serviceModel>

And I'm not sure where to put the OperationTimeout property.

Thanks.

Omar

Set the timeout properties of WCF application to increase the default timeout. This can be done on the client side programmically or with a client side App.Config or a Web.config.

You can configure the OperationTimeout property for Proxy in the WCF client code.

For example

DirectCast(service, IContextChannel).OperationTimeout = New TimeSpan(0, 0, 240)

Refer: http://www.codeproject.com/KB/WCF/WCF_Operation_Timeout_.aspx

Another thing. The method time span is long enough (the default timeout value is 60 secs) to execute it (it's just a query of one table), and I have no idea why, when executes the first time, it works, and the second time it didn't.

Well, Someone might wanna know this...

I solved the problem putting the close method at the end of the call.

'some code ...

            Dim oAlmacenWCF As New repositorio.RepositorioClient
            Dim oListaAlmacenBE As List(Of BE.Almacen)
            oListaItemAlmacenBE = oAlmacenWCF.ListarAlmacen(item_id)
            oAlmacenWCF.Close()

'some code

I hope this helps someone...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.