将大数据发送到WCF服务会返回“ 504(网关超时)错误”

时间:2018-12-27 07:39:35

标签: asp.net-mvc wcf

我正在尝试详细描述我的问题。我们的目标是将对象发送到处理的wcf服务,并用另一个对象进行响应。如果我们发送1000、2000对象,则结果成功。但是,当我们增加对象的大小(如10.000、20.000)时,服务器等待1-1.30分钟,然后响应504网关错误。 首先,在客户端,我们上传文件,然后将其读取到服务器端。我们初始化读取数据的对象,然后将该对象发送给服务。我的控制器如下:

public ActionResult SaleNotification(NOTIFICATION_OBJECT notificationItem, HttpPostedFileBase files)
{

    if (files != null)
    {
        List<NOTIFICATION_ITEM_OBJECT> fileItems = new List<NOTIFICATION_ITEM_OBJECT>();
        using (var package = new StreamReader(files.InputStream))
        {
            package.ReadLine();
            while (!package.EndOfStream)
            {

                var values = package.ReadLine().Split(';');
                if (values[0] != "" && values[1] != "" && values[2] != "" && values[3] != "")
                {
                    fileItems.Add(new NOTIFICATION_ITEM_OBJECT
                    {
                        GT = values[0],
                        SN = values[1].ToUpper(),
                        BN = values[2].ToUpper(),
                        XD = values[3]
                    });
                }
            }
        }
        notificationItem.NOTIFICATION_ITEMS.AddRange(fileItems);
    }
    var res = _serviceRepository.SendNotification(Security.Decrypt(SERVICE_PASS_ENCRYPT, true), notificationItem);
    return PartialView("PartialResult", res);

}

发送通知到服务部分,我试图一次发送整个对象,也许那部分我的方法是错误的。这是我的代码:

    public NOTIFICATION_RESULT_OBJECT SendNotification( string password, NOTIFICATION_OBJECT notification)
    {
        var res = new NOTIFICATION_RESULT_OBJECT();
        try
        {
            var client = new serviceClient();
            if (client.ClientCredentials != null)
            {
                client.ClientCredentials.UserName.Password = password;        
            }

            using (new OperationContextScope(client.InnerChannel))
            {
                #region header
                var requestMessage = new HttpRequestMessageProperty();   
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                #endregion

               //Some codes service request initialize

                ServicePointManager.ServerCertificateValidationCallback = delegate (object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
                var response = client.notify(serviceRequest);

                res.NOTIFICATION_ID = response.NOTIFICATIONID;
                foreach (var item in response)
                    res.PRODUCT_RESULT_LIST.Add(new PRODUCT_RESULT()
                    {
                        GT = item.GT,
                        RC = item.RC,
                        SN = item.SN,
                        BN = item.BN,
                        XD = item.XD.ToString("dd/MM/yyyy", new CultureInfo("tr-TR")),
                    });
                return res;
            }

        }
        catch (Exception ex)
        {

            Log4NetFunction.InsertLog(ex);
            return res;
        }
    }
}

我的绑定上有一个关于maxReceivedMessageSize,sendTimeout,receivedTimeout等的配置。这是我的绑定之一的示例:

<binding name="serviceBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"  openTimeout="00:10:00" 
             closeTimeout="00:10:00"  sendTimeout="00:15:00" receiveTimeout="00:10:00">
      <security mode="Transport">
        <transport clientCredentialType="Basic" proxyCredentialType="Basic" realm="" />
        <message clientCredentialType="Certificate" algorithmSuite="Default" />
      </security>
    </binding>

在调试中,我找不到任何错误,它在本地成功发送了20000个对象,或者在服务器上没有有关此错误的日志。所以我找不到任何解决方案。我怎么解决这个问题?我的方法不对吗?

1 个答案:

答案 0 :(得分:0)

也许您的服务拒绝将具有这么多数据成员的数据序列化。

请尝试设置绑定的readerQuotas属性。

<binding  allowCookies="false"  maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647"   openTimeout="00:10:00" 
         closeTimeout="00:10:00"  sendTimeout="00:15:00" receiveTimeout="00:10:00"  >
      <readerQuotas maxArrayLength="2147483647" maxNameTableCharCount="2147483647"
          maxStringContentLength="2147483647" maxDepth="2147483647"
          maxBytesPerRead="2147483647" />
      <security mode="None" />
    </binding>