Why does Microsoft Dynamics CRM 4.0 occasionally fail when calling the RetrieveMultiple web service?
I have C# using the CRM RetrieveMultiple web service to update Lead entity records. Everything works perfectly 80% of the time.
About 20% of the time, it fails. On failure, here is the SoapException Detail.InnerText property:
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
Here is the code that makes the web service call:
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 ret开发者_运维技巧rieveLeads = 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;
}
}
I have pretty much ruled out that it is a problem with the VPN or CRM 4.0 itself.,,I have not been able to reproduce the error in a controlled way. Please advise if you have tips, ideas, or solutions!
Thanks
How often are you retrieving the records? Are you also updating them afterwards? Under high volume (and with default IIS/Windows Server settings) I have seen the server run out of available ports, since with every call to the CRM Service (even using the same service object) CRM opens up another port.
精彩评论