首页 > 解决方案 > microservices 连接尝试失败,因为连接方在一段时间后没有正确响应

问题描述

我有使用微服务的客户端应用程序,我正在使用下面的代码来调用微服务。

使用(HttpClient 客户端 = 新 HttpClient())

            {
                var buffer = System.Text.Encoding.UTF8.GetBytes(new JavaScriptSerializer().Serialize(AttModel));
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                string url = "http://servicename.com:60003/xxx/yyy";
                HttpResponseMessage message = client.PostAsync(url, byteContent).Result;
                string response = message.Content.ReadAsStringAsync().Result;

                if (response != "")
                {
                    //lblInsert.Text = "Your values inserted successfully and the Transaction Title is : " + response;
                }
            }

当我从此代码调用微服务时,它返回以下错误。连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应 10.xx.yy.zz:60001

我也保持超时无限

            client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);

之后我也关闭了防火墙,但没有用。

这个微服务在同一台机器上大摇大摆地工作。

请帮助任何人,在此先感谢!

标签: c#asp.net-mvcwcfasp.net-web-apidotnet-httpclient

解决方案


推荐阅读