3

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 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;
    }
}

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

pnuts
  • 58,317
  • 11
  • 87
  • 139

1 Answers1

1

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.

Matt
  • 4,656
  • 1
  • 22
  • 32
  • I am using RetriveMultiple to determine if there is an existing Lead record (using Email Address as the key). If there is, then the existing Lead record is updated. If there is not, a new Lead record is created. Usually between 10-20 new Leads are created each day, and an additional 2-5 fail. I tried enabling tracing in CRM, which revealed nothing, no errors, which makes me think that it could be a networking problem, maybe port related. I increased the MaxUserPort TCPTimedWaitDelay registry settings to see if that would help but didn't make a difference. Any other ideas? Thanks!! – Lou Mintzer Feb 28 '11 at 15:26
  • Any thoughts on how setting the UnsafeAuthenticatedConnectionSharing = true; property could cause this problem? – Lou Mintzer Feb 28 '11 at 22:25
  • If you're impersonating users, or multiple users are running the same process, UnsafeAuthenticatedConnectionSharing could cause security issues, although I don't believe I've seen it ever cause a Socket Exception. – Matt Feb 28 '11 at 22:51
  • Also, if you updated the MaxUserPort and TCPTimedWaitDelay, did you restart the server? I believe one if not both of those require a server restart. – Matt Feb 28 '11 at 22:52