У меня есть C #, использующий веб-сервис CRM RetrieveMultiple для обновления записей сущностей Lead.Все отлично работает в 80% случаев.
Примерно в 20% случаев происходит сбой.В случае неудачи вот свойство SoapException Detail.InnerText:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Вот код, который делает вызов веб-службы:
local.mycompany.crm.CrmAuthenticationToken token;
local.mycompany.crm.CrmService service;
local.mycompany.crm.lead tourRequestLead = new local.mycompany.crm.lead();
tourRequestLead.emailaddress1 = "xxxxxxx@mycompany.com";
token = new local.mycompany.crm.CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "mycompanyCRM";
service = new local.mycompany.crm.CrmService();
service.CrmAuthenticationTokenValue = token;
service.UnsafeAuthenticatedConnectionSharing = true;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Url = "http://crm.mycompany.local/mscrmservices/2007/crmservice.asmx";
// Create the ColumnSet that indicates the properties to be retrieved.
local.mycompany.crm.ColumnSet cols = new local.mycompany.crm.ColumnSet();
// Set the properties of the ColumnSet.
cols.Attributes = new string[] { "emailaddress1", "new_initialtourrequestlistingid", "description" };
// Create the ConditionExpression.
local.mycompany.crm.ConditionExpression condition = new local.mycompany.crm.ConditionExpression();
// Set the condition for the retrieval to be when the contact's address' city is Sammamish.
condition.AttributeName = "emailaddress1";
condition.Operator = local.mycompany.crm.ConditionOperator.Equal;
condition.Values = new string[] { tourRequestLead.emailaddress1 };
// Create the FilterExpression.
local.mycompany.crm.FilterExpression filter = new local.mycompany.crm.FilterExpression();
// Set the properties of the filter.
filter.FilterOperator = local.mycompany.crm.LogicalOperator.And;
filter.Conditions = new local.mycompany.crm.ConditionExpression[] { condition };
// Create the QueryExpression object.
local.mycompany.crm.QueryExpression query = new local.mycompany.crm.QueryExpression();
// Set the properties of the QueryExpression object.
query.EntityName = local.mycompany.crm.EntityName.lead.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
// Retrieve the leads.
local.mycompany.crm.BusinessEntityCollection retrieveLeads = null;
try
{
retrieveLeads = service.RetrieveMultiple(query);
}
catch (Exception exp)
{
Console.WriteLine("RetrieveMultiple " + exp);
CountError += 1;
}
if ((retrieveLeads != null) && (retrieveLeads.BusinessEntities.Length > 0))
{
try
{
foreach (local.mycompany.crm.lead rlead in retrieveLeads.BusinessEntities)
{
string strNotes = rlead.description;
}
}
catch (Exception exp)
{
Console.WriteLine("Reard " + exp);
CountError += 1;
}
}
Я почти исключилпроблема с самой VPN или CRM 4.0. Я не смог воспроизвести ошибку контролируемым образом.Пожалуйста, сообщите, если у вас есть советы, идеи или решения!
Спасибо