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

问题描述 投票:0回答:1

我想详细描述我的问题。我们的目标是将对象发送到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对象成功或在服务器上没有关于此错误的日志。所以我找不到任何解决方案。我怎么解决这个问题?我的方法有误吗?

asp.net-mvc wcf
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.