次の 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 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>
つまり、すべてのタイムアウト値は 5 分に設定されます。
Windows Phone 8 クライアント アプリケーションがサービスを呼び出します。
namespace TeaClient
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
var client = new TeaServiceClient();
client.PrepareTeaCompleted += Client_PrepareTeaCompleted;
client.PrepareTeaAsync("Rooibos");
}
private void Client_PrepareTeaCompleted(object sender, PrepareTeaCompletedEventArgs e)
{
tb.Text = e.Result;
}
}
}
「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>
問題: 1 分後にクライアント側で CommunicationException がスローされます。
$exception {System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
--- End of inner exception stack trace ---
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at TeaClient.TeaService.TeaServiceClient.TeaServiceClientChannel.EndPrepareTea(IAsyncResult result)
at TeaClient.TeaService.TeaServiceClient.TeaClient.TeaService.ITeaService.EndPrepareTea(IAsyncResult result)
at TeaClient.TeaService.TeaServiceClient.OnEndPrepareTea(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)} System.Exception {System.ServiceModel.CommunicationException}
これがなぜなのかわかりません。WPF デスクトップ アプリケーションにまったく同じ WCF クライアント固有のコードを実装すると、例外はスローされません。Thread.Sleep(61000) を削除する限り、サービスが正常に動作し、Windows Phone アプリケーションも正常に動作することを確認できます。私の「実際の」運用シナリオ (この簡略化された例が反映されています) では、クライアントは CommunicationException をスローすることなく 1 分以上待機できる必要があります。この例は、WPF アプリケーションから同じことを行った場合に機能するため、問題が Windows Phone プラットフォームの制限に関連しているのではないかと疑っています。しかし、Windows Phone では WCF 呼び出しに 1 分以上かかるという情報は見つかりません。
さらに、次のようにクライアント プロキシで OperationTimeout を設定しようとしました。
client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(5.0);
しかし、運が悪い。どんな提案でも大歓迎です。
編集: nvoigt でマークされた重複した質問は、HttpClient に関連しています。この質問は、BasicHttpBinding を使用する WCF クライアント プロキシに関するものです。根本的な問題は間違いなくまったく同じであるため、プラットフォームの制限であると結論付けました.