我正在尝试使用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>
我将不胜感激任何帮助或建议。预先感谢。
答案 0 :(得分:0)
我已经能够解决此问题并发布答案,因为它可以帮助其他人为类似的问题而苦苦挣扎。 Salesforce市场营销云API(包括SOAP和REST)已停止支持默认的TLS 1.0协议。因此,在向API发送任何请求之前,我需要添加以下代码。
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;
下面的链接对相同的见解有更多解释。