WCF via Windows phone doesn't work at the first time

Go To StackoverFlow.com

1

I have a windows phone application that uses WCF services to get and store data on the DB. I added a service reference to the WCF service and VS generated the client proxy and the configuration file.

The problem starts when I try to call methods on the server.

The first call causes a timeout, the server doesn't even receive the request. Only in the second call the server receives the request.

Win7MobileServiceClient client = new Win7MobileServiceClient();

client.GetUserCompleted += new EventHandler<ServiceReference1.GetUserCompletedEventArgs>(client_GetUserCompleted);

client.GetUserAsync(int.Parse(txtID.Text));

Thanks

2012-04-04 07:59
by user556882


0

This is probably due to the warm up process of service. First time that a WCF service is invoked it takes some time (I think is compiling it). It will happen again if you recycle app pools.

In order to be sure try this

  1. Deploy WCF Service
  2. Invoke WCF service from windows
  3. Invoke it from windows mobile

If this is the case probably the reason is that default timeout in windows mobile client maybe is smaller than stantaderd (1min). There is a number of solutions you can do like

  • Increase windows mobile time out
  • Invoke service everytime you deploy it (for example have some sort of smoke test in Selenium. The problem of this approach that you will have again same problem after recycling of app pools)

You can check this similar question: WCF Performance Slow for the first call

2012-04-04 11:11
by Oscar Foley
I don't think that is the problem. If I try to invoke the method twice in a row, the method works as expected - user556882 2012-04-04 13:08
Then... you have a problem :) Try comparing app.config of client and service and check that buffer sizes and message sizes. - Oscar Foley 2012-04-04 13:58
Maybe invoking emthod twice in a row give times to server to build. Say that timeout is 10 secs and takes 11 to build.. first invocation fails but second works because it is 1sec to build + 1 sec to execute.. - Oscar Foley 2012-04-04 14:13
I tried all...Still the same proplem. I found that the problem is in the windows phone client. I call the service async from console, win forms and silverlight applications. Maybe you wrote something similar? with wcf and windows phone clien - user556882 2012-04-04 20:35
Ads