peterc
peterc

Reputation: 7863

WCF in Silverlight - how to set change the default timeout of 1 minute

I have a WCF service I am connecting to in in a Silverlight project. The task the service needs to do takes over a minute (which is fine), but I get an error. I communicate to it via a proxy (created by dev studio when you add a service reference)

The HTTP request to 'http://localhost/ImporterService.svc' has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout.

(where ImporterService is my service)

I Have read all sort of posts for the last 3 days about increasing the following.

receiveTimeout="00:10:00"
sendTimeout="00:10:00"
openTimeout="00:10:00"
closeTimeout="00:10:00"

Nothing has worked, it still times out after 1 minute!

Ok, so in the file ServiceReferences.ClientConfig generated I have added the values in the following place

<configuration>
  <system.serviceModel>
  <bindings>
   <basicHttpBinding>
   <binding name="BasicHttpBinding_ImporterService" maxBufferSize="2147483647"
      receiveTimeout="00:10:00"
      sendTimeout="00:10:00"
        openTimeout="00:10:00"
        closeTimeout="00:10:00"
        maxReceivedMessageSize="2147483647">
        <security mode="None" />
        </binding>
        ....

This timeout appear to be occurring on the client side (eg I can make it happen by adding a 1 minutes sleep in the service code)

Question1 So, in my case is it only the client side I need to change.

At any rate in the web.config In the web.config, I added the block

inside the existing <basicHttpBinding> as shown below


 ><basicHttpBinding>
    ><binding name="downloadBinding" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
    ><readerQuotas maxArrayLength="2000000" maxStringContentLength="2000000" />
    ></binding>
    >    
    ><binding name="BasicHttpBinding_IImporterService" maxBufferSize="2147483647"
    >receiveTimeout="00:10:00"
    >sendTimeout="00:10:00"
    >openTimeout="00:10:00"
    >closeTimeout="00:10:00"
    >maxReceivedMessageSize="2147483647">
    ><security mode="None" />
    ></binding>
    >    
    ></basicHttpBinding>            
    ></bindings>

Note I am using the names BasicHttpBinding_IImporterService (other posts have used random names where they are not even the same on the client and server! e.g.

I also have <httpRuntime executionTimeout set to a huge value.

The time out just does not increase. It is still 1 minute.

So, big questions

1. What an I doing wrong, am I putting these settings in the wrong place?
2. Is it just client side I need to do
3. Perhap it can be done in code if these config settings don't work

Eg where I use it, I instantiated using

ImporterServiceClient importerService = new ImporterServiceClient("*", new >EndpointAddress(ServicePath));

I know there are lots other other post, but, but most just include the properties, and not exactly where to set them, so obviously mine are in the wrong place?

Any help would be greatly appreciated. All I want to do is increase a time out (in code, config, anywhere that will actually work)!

Thanks in advance to any one that can help here Pete

Upvotes: 0

Views: 5784

Answers (2)

peterc
peterc

Reputation: 7863

@Std_Net, thank you very much for the reply. Not too long after I posted this, I managed to get it working (though I had been struggling for a few days!)

The above was exactly what I was adding the timeout setting, for for some reason, the setting were just not taking hold for me. I found an exampole where these were set in code, and when I tried that, they finally appeared to work.

You are correct, I did not need to do anyhting on the server site (web.config), only client side.

Just incase anyone else ever need to know this (ie new to WCF like myself) here is what worked for me at least...

private readonly ImporterServiceClient m_importerService; ...

m_importerService = new ImporterServiceClient("*", new EndpointAddress(ServicePath));            
const int timeoutMinutes = 15;
m_importerService.Endpoint.Binding.OpenTimeout = TimeSpan.FromMinutes(timeoutMinutes);
m_importerService.Endpoint.Binding.SendTimeout = TimeSpan.FromMinutes(timeoutMinutes);

Upvotes: 0

Std_Net
Std_Net

Reputation: 1096

In web.config no need add any timeout data. add timeout settings to your SL app. When you add ServiceRefferences into you project VisualStudio must generate file

ServiceReferences.ClientConfig

I have this config

<?xml version="1.0" encoding="utf-8"?>

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>

            <binding name="BasicHttpBinding_IEventsService" closeTimeout="01:59:00"
                receiveTimeout="01:59:00" sendTimeout="01:59:00" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://mySite/MyService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEventsService"
            contract="EventService.IEventsService" name="BasicHttpBinding_IEventsService" />

    </client>
</system.serviceModel>

You can set timeout params as you need. Hope this help.

Upvotes: 1

Related Questions