简体   繁体   English

Azure长期运行的外部Web服务调用

[英]Azure Long-running external web service calls

I've written a windows service in C# that interfaces with a third party via external web service calls (SOAP). 我已经用C#编写了一个Windows服务,该服务通过外部Web服务调用(SOAP)与第三方连接。 Some of the calls respond quickly and some slowly 有些电话反应很快,有些反应慢

(for example, quick = retrieving a list of currencies; slow = retrieving a historical value of currencies per product over many years) (例如,快速=检索货币列表;慢速=检索多年以来每种产品的货币历史价值)

The external service works fine when I run it on my local machine - the quick calls runs for about 20 seconds; 当我在本地计算机上运行外部服务时,它可以正常工作-快速调用运行约20秒钟; the slow calls runs for about 30 minutes. 慢速通话大约持续30分钟。 I can't do anything about the speed of the 3rd party service and I don't mind the time it takes to return an answer.. 我对第三方服务的速度无能为力,我也不介意返回答案所花费的时间。

My problem is that when I deploy my service to my Azure Virtual Machine: The quick call works perfectly like it does locally; 我的问题是,当我将服务部署到Azure虚拟机时:快速调用的工作原理与本地调用完全相同; the slow ones just never returns anything. 慢的人永远不会返回任何东西。 I have tried exception handling, logging to files, logging to eventLog. 我尝试了异常处理,记录到文件,记录到eventLog。

There is no clear indication of what goes wrong - it just seems that for whatever reason - the long running web service calls, never return successfully to Azure. 没有明确表明出了什么问题–似乎出于某种原因-长时间运行的Web服务调用永远不会成功返回Azure。

I've read somewhere that there is some sort of connection-recycling happening every 4 minutes, which I suspect is somehow causing the external web service response to land up somewhere in a void with the load balancer or whatever not knowing any longer whom requested the content. 我读过某个地方,每隔4分钟就会发生某种形式的连接回收,我怀疑这是某种原因导致外部Web服务响应在负载均衡器或其他不再知道谁要求负载均衡器的地方降落了内容。

I start by creating the request with the relevant SOAP envelope, like this: 我首先使用相关的SOAP信封创建请求,如下所示:

HttpWebRequest tRequest = (HttpWebRequest)WebRequest.Create(endpoint);

Then i set the stuff, like this: 然后,我将其设置为:

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

Anyone else experienced something similar and any suggestions how to solve it please? 其他人也遇到过类似的事情,请问如何解决它的建议?

Many thanks 非常感谢

http://www.fourtimesfour.co.za http://www.fourtimesfour.co.za

When you deploy to Azure (Cloud Service, Virtual Machine) there is always the Azure Load Balancer, which sits between your VMs and the Internet. 当您部署到Azure(云服务,虚拟机)时,总会有Azure负载平衡器,它位于您的VM和Internet之间。

In order to keep resources equally available to all the cloud users, Azure Load Balancer will kill idle connections. 为了使资源平等地可供所有云用户使用,Azure负载平衡器将终止空闲连接。 What idle for Azure LB is - default is 4 minutes of no communication sent over established channel. Azure LB的空闲时间是-默认是4分钟,没有通过已建立的通道发送通信。 So if you call a web service and there is absolutely no response on the pip for 4 minutes - your connection will get terminated. 因此,如果您致电网络服务,并且在4分钟内绝对没有任何响应,您的连接将被终止。

You can configure this timeout, but I would really argue the need for keeping connection open that long. 您可以配置此超时,但是我真的认为需要保持连接打开这么长时间。 Yes, you can do nothing about it, besides looking for a service which has better design (ie either returns responses faster, or implements asynchronous calls where the first call to the service will just give you a task id, using which you can poll periodically to get a result) 是的,除了寻找设计更好的服务(即返回响应更快,或者实现异步调用,其中对服务的第一次调用只会给您一个任务ID,您可以使用它定期轮询),您什么也不能做得到结果)

Here is a good article on how to configure the Azure Load Balancer timeout . 这是一篇有关如何配置Azure负载平衡器超时的好文章 Be aware, the maximum timeout for Azure LB is 30 minutes. 请注意,Azure LB的最大超时为30分钟。

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

相关问题 如何中断长时间运行的Web服务调用 - how to interrupt a long-running Web Service call 使用多个长时间运行的操作优化ASMX Web服务 - Optimizing an ASMX web service with Multiple Long-Running Operations 正在进行长时间运行的调用异步这么简单吗? - Is making long-running calls async this simple? ASP.NET Web API - 多个长时间运行的 ZDB974238714CA8DE634A7CE1D083A1 调用最佳实践? - ASP.NET Web API - Multiple Long-Running API calls best practices? 长期运行的WCF服务即将终止的原因是什么? - Reasons for long-running WCF service dying? 创建长期运行的工作流服务 - Creating a long-running Workflow Service 长期运行的 Azure Web 角色上的异常“目标主体名称不正确” - Exception “The target principal name is incorrect” on long-running Azure Web role 如何通过Web服务(如工作单元)实施长时间运行的事务 - How to implement long-running transactions over a web service, like unit of work 在执行长时间运行的数据库任务时处理Web服务超时 - Handling Web Service Timeouts While Performing Long-Running Database Tasks 在ASP.net Web API 2服务中处理长时间运行的进程 - Handling Long-Running Processes in an ASP.net Web API 2 Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM