营销云 SOAP API 检索请求超时异常

Marketing cloud SOAP API Retrieve request timeout exception

我正在尝试使用 SOAP API 从营销云下载订阅者,并且在几次迭代后抛出以下异常。

它不会一直失败。有时它完成 50 次迭代并失败,有时它在 5 或 10 次迭代后失败。

这是我用来发出检索请求的代码:

public List<Subscriber> GetSubscribers(string RequestId = null)
    {
        string message = string.Empty;
        _lstSubscribers = new List<Subscriber>();
        SoapClient client = new SoapClient();
        client.ClientCredentials.UserName.UserName = _username;
        client.ClientCredentials.UserName.Password = _password;

        RetrieveRequest retrieveRequest = new RetrieveRequest();
        retrieveRequest.ObjectType = "Subscriber";

        string[] props = { "Client.ID", "CreatedDate", "EmailAddress", "EmailTypePreference", "ID", "PartnerKey", "SubscriberKey", "UnsubscribedDate" };
        retrieveRequest.Properties = props;

        retrieveRequest.ClientIDs = new ClientID[] { _clientID };
        //retrieveRequest.QueryAllAccounts = true;
        //retrieveRequest.QueryAllAccountsSpecified = true;

        String requestId = RequestId; 
        String response = string.Empty;
        int tryCount = 0;
        try
        {
            RunRetrieveRequest(client, out requestId, out response, retrieveRequest);
        }
        catch (Exception ex)
        {
            if (response == "MoreDataAvailable")
            {
                tryCount++;
                if (tryCount <= 10)
                {

                }

                retrieveRequest.ContinueRequest = requestId;
                RunRetrieveRequest(client, out requestId, out response, retrieveRequest);
            }
        }
        return _lstSubscribers;
    }

    private void RunRetrieveRequest(SoapClient client, out string RequestID, out string Response, RetrieveRequest Request)
    {
        List<Subscriber> lstSubscribers = new List<Subscriber>();
        APIObject[] results = null;
        do
        {
            Response = client.Retrieve(Request, out RequestID, out results);

            Subscriber subscriber = null;
            if (Response != null && results != null)
            {
                foreach (var result in results)
                {
                    subscriber = (Subscriber)result;
                    _lstSubscribers.Add(subscriber);
                }
            }
            Request = new RetrieveRequest();
            Request.ContinueRequest = RequestID;
        } while (Response == "MoreDataAvailable");
    }

这是配置。我曾尝试将超时属性从 30 更改为 59,但这没有帮助。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="SoapBinding">
                <security mode="Transport" />
            </binding>
            <binding name="SoapBinding1" />
        </basicHttpBinding>
      <customBinding>
        <binding name="SoapBinding" closeTimeout="00:59:00" openTimeout="00:59:00" receiveTimeout="00:59:00" sendTimeout="00:59:00">
          <security authenticationMode="UserNameOverTransport">
            <secureConversationBootstrap />
          </security>
          <textMessageEncoding messageVersion="Soap11WSAddressingAugust2004" />
          <httpsTransport maxReceivedMessageSize="655360000" />
        </binding>
      </customBinding>
    </bindings>
    <client>
        <endpoint address="https://mySubDomain.soap.marketingcloudapis.com/Service.asmx"
            binding="customBinding" bindingConfiguration="SoapBinding"
            contract="sfmc.Soap" name="Soap" />
    </client>
</system.serviceModel>

如有任何帮助或建议,我将不胜感激。提前致谢。

我已经能够解决这个问题并发布答案,因为它可能会帮助其他遇到类似问题的人。 Salesforce 营销云 API(SOAP 和 REST)已停止支持默认的 TLS 1.0 协议。所以我需要在向 API.

发送任何请求之前添加以下代码
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

以下 link 对此有更多解释。