【发布时间】:2015-07-16 21:40:31
【问题描述】:
我用 C# 编写了一个 Windows 服务,它通过外部 Web 服务调用 (SOAP) 与第三方交互。有的电话反应快,有的反应慢
(例如,快速 = 检索货币列表;慢速 = 检索每个产品多年来的货币历史价值)
当我在本地机器上运行外部服务时,它运行良好 - 快速调用运行大约 20 秒;慢速通话大约持续 30 分钟。我对 3rd 方服务的速度无能为力,我不介意返回答案所花费的时间..
我的问题是,当我将服务部署到我的 Azure 虚拟机时: 快速调用与本地一样完美;慢的永远不会返回任何东西。我尝试过异常处理、记录到文件、记录到 eventLog。
没有明确指示出了什么问题 - 似乎无论出于何种原因 - 长时间运行的 Web 服务调用,永远不会成功返回到 Azure。
我在某处读到,每 4 分钟就会发生某种连接回收,我怀疑这会以某种方式导致外部 Web 服务响应在负载均衡器或其他任何不知道的地方降落谁请求了内容。
我首先使用相关的 SOAP 信封创建请求,如下所示:
HttpWebRequest tRequest = (HttpWebRequest)WebRequest.Create(endpoint);
然后我设置这些东西,像这样:
tRequest.ClientCertificates.Add(clientCertificate);
tRequest.PreAuthenticate = true;
tRequest.KeepAlive = true;
tRequest.Credentials = CredentialCache.DefaultCredentials;
tRequest.ContentLength = byteArray.Length;
tRequest.ContentType = @"text/xml; charset=utf-8";
tRequest.Headers.Add("SOAPAction", @"http://schemas.xmlsoap.org/soap/envelope/");
tRequest.Method = "POST";
tRequest.Timeout = 3600000;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; //the SSL certificate is bad
Stream requestStream = tRequest.GetRequestStream();
requestStream.Write(byteArray, 0, byteArray.Length);
requestStream.Close();
requestStream.Dispose(); //works fine up to this point.
WebResponse webResponse = tRequest.GetResponse(); //The slow calls never make it past this. Fast one does
有没有其他人遇到过类似的情况,请问有什么解决办法吗?
非常感谢
【问题讨论】:
标签: c# web-services azure soap