C# 通信异常在一分钟后发生(从windows phone 8应用程序调用wcf服务期间)
我已经实现了以下WCF服务:C# 通信异常在一分钟后发生(从windows phone 8应用程序调用wcf服务期间),c#,.net,wcf,windows-phone-8,communicationexception,C#,.net,Wcf,Windows Phone 8,Communicationexception,我已经实现了以下WCF服务: namespace TeaService { public class TeaService : ITeaService { public string PrepareTea(string tea) { System.Threading.Thread.Sleep(61000); return "A nice cup of " + tea + " tea will be r
namespace TeaService
{
public class TeaService : ITeaService
{
public string PrepareTea(string tea)
{
System.Threading.Thread.Sleep(61000);
return "A nice cup of " + tea + " tea will be ready in a few minutes.";
}
}
}
服务使用默认的basichttpbinding,绑定配置如下:
<bindings>
<basicHttpBinding>
<binding openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" closeTimeout="00:05:00"></binding>
</basicHttpBinding>
</bindings>
var client = new TeaServiceClient();
client.ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan.FromMinutes(5);
“tb”是在xaml视图中定义的文本框
在ServicesReferences.ClientConfig中,basicHttpBinding的超时值设置如下:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITeaService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" closeTimeout="00:05:00">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
但是没有运气。欢迎提出任何建议
编辑:nvoigt标记的重复问题与HttpClient相关。这个问题是关于使用BasicHttpBinding的WCF客户端代理的。基本问题毫无疑问是完全相同的,因此我们得出结论,这是一个平台限制。Windows Phone应用程序没有app.config文件,因此指定的超时都不适用。相反,您需要在客户端实例上进行如下设置:
<bindings>
<basicHttpBinding>
<binding openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" closeTimeout="00:05:00"></binding>
</basicHttpBinding>
</bindings>
var client = new TeaServiceClient();
client.ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan.FromMinutes(5);
这是正确的(不存在app.config),但ServiceReferences.ClientConfig确实存在,并且从那里设置的超时值确实适用于客户端代理。因此,已在客户端上正确设置超时值。如果我检查client.ChannelFactory.Endpoint.Binding.SendTimeout,我会看到我在ServiceReferences.ClientConfig.com中指定的值。您能改用WebSocket吗?如果使用NetHttpBinding并使用回调协定,则可以将请求发送到服务器,然后服务器在回调上发送响应。如果这是您的选项,我可以提供更多信息。不幸的是,没有。BasicHttpBinding是Windows Phone 8.0上唯一受支持的wcf绑定。。。或也许可以通过一个可移植的类库来实现?谢谢你的建议。
var client = new TeaServiceClient();
client.ChannelFactory.Endpoint.Binding.SendTimeout = new TimeSpan.FromMinutes(5);