简体   繁体   English

WCF 通过 Windows 手机第一次打不通

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

I have a windows phone application that uses WCF services to get and store data on the DB.我有一个 windows 电话应用程序,它使用 WCF 服务来获取和存储数据库中的数据。 I added a service reference to the WCF service and VS generated the client proxy and the configuration file.我添加了对 WCF 服务的服务引用,VS 生成了客户端代理和配置文件。

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谢谢

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) .第一次调用 WCF 服务需要一些时间(我认为正在编译) It will happen again if you recycle app pools.如果您回收应用程序池,它会再次发生。

In order to be sure try this为了确保尝试这个

  1. Deploy WCF Service部署 WCF 服务
  2. Invoke WCF service from windows从 windows 调用 WCF 服务
  3. Invoke it from windows mobile从 windows 手机调用它

If this is the case probably the reason is that default timeout in windows mobile client maybe is smaller than stantaderd (1min).如果是这种情况,可能是因为 windows 移动客户端中的默认超时可能小于 stantaderd(1 分钟)。 There is a number of solutions you can do like您可以使用多种解决方案

  • Increase windows mobile time out增加windows移动超时
  • 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)每次部署它时调用服务(例如在 Selenium 中进行某种冒烟测试。这种方法的问题是在回收应用程序池后您将再次遇到同样的问题)

You can check this similar question: WCF Performance Slow for the first call您可以查看类似的问题: WCF Performance Slow for the first call

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM