Azure的长期运行的外部Web服务调用 [英] Azure Long-running external web service calls

查看:158
本文介绍了Azure的长期运行的外部Web服务调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在C#中的窗口服务,通过外部Web服务调用(SOAP)第三方接口。一些呼叫迅速作出反应,有的慢慢

I've written a windows service in C# that interfaces with a third party via external web service calls (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)

外部服务的工作时,我在我的本地计算机上运行良好 - 快速调用运行约20秒;缓慢调用运行约30分钟。我不能做任何事情对第三方服务的速度和我不介意它需要返回一个答案的时候。

The external service works fine when I run it on my local machine - the quick calls runs for about 20 seconds; the slow calls runs for about 30 minutes. 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..

我的问题是,当我部署我的服务我的Azure虚拟机:快速调用工作完全像它在本地做的事情;慢的人只是从未返回任何东西。我曾尝试异常处理,记录到文件中,记录到事件日志。

My problem is that when I deploy my service to my Azure Virtual Machine: The quick call works perfectly like it does locally; the slow ones just never returns anything. I have tried exception handling, logging to files, logging to eventLog.

有是哪里出了问题没有明确的迹象 - 这似乎只是出于某种原因 - 长时间运行的Web服务调用,从来没有成功地返回到Azure的

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.

我读的地方,有某种联系,回收每4分钟,我怀疑是某种导致外部Web服务响应与负载均衡器或其他不知道任何不再是空洞的地方降落了发生其中要求的内容。

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.

我开始通过创建有关SOAP信封的要求,如:

I start by creating the request with the relevant SOAP envelope, like this:

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?

非常感谢

http://www.fourtimesfour.co.za

推荐答案

当你部署到Azure的(云服务,虚拟机)总是有Azure的负载均衡,从而虚拟机与Internet之间的坐镇。

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的LB是 - 默认为4分钟内无发送以确立渠道的沟通。所以,如果你调用Web服务也绝对4分钟画中画没有反应 - 你的连接将被终止

In order to keep resources equally available to all the cloud users, Azure Load Balancer will kill idle connections. What idle for Azure LB is - default is 4 minutes of no communication sent over established channel. So if you call a web service and there is absolutely no response on the pip for 4 minutes - your connection will get terminated.

您可以配置此超时,但我真的认为保持连接打开,长期的需求。是的,你可以做什么吧,除了寻找有更好的设计服务(即或者返回的响应速度更快,或实现异步调用哪里该服务的第一次调用只会给你一个任务ID,使用它可以定期轮询得到的结果)

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 (i.e. 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)

<一个href=\"http://azure.microsoft.com/blog/2014/08/14/new-configurable-idle-timeout-for-azure-load-balancer/\"相对=nofollow>这里是如何配置的Azure负载平衡器超时好文章。要知道,对于Azure的LB最大超时时间为30分钟。

Here is a good article on how to configure the Azure Load Balancer timeout. Be aware, the maximum timeout for Azure LB is 30 minutes.

这篇关于Azure的长期运行的外部Web服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆