1

我有一个自定义应用程序,它使用 crmservice.asmx 从动态 crm 4 中检索联系人。

问题:我在自定义应用程序中搜索联系人但没有找到。我去 MSCRM 并创建联系人。当我尝试在我的自定义应用程序中再次搜索时,我仍然找不到该联系人。

它必须为 crmservice.asmx 缓存,因为当我在 10 分钟后尝试时,会在我的自定义应用程序中找到该联系人。

但是如何管理 crmservice.asmx 上的缓存设置?

我的实例化代码

Private Const CRMServiceUrl As String = "https://*****/mscrmservices/2007/crmservice.asmx"
Private Const MetadataServiceUrl As String = "https://*****/MSCRMServices/2007/MetadataService.asmx"
Private Const OrganizationName As String = "****"
Private Const Username As String = "****"
Private Const Password As String = "****"
Private Const Domain As String = "****"

Private ReadOnly _service As CrmService.CrmService
Private ReadOnly _metadataService As MetadataService.MetadataService


Public Sub New()
    Dim crmServiceToken As New CrmAuthenticationToken()
    crmServiceToken.AuthenticationType = Microsoft.Crm.Sdk.AuthenticationType.AD
    crmServiceToken.OrganizationName = OrganizationName

    Dim metadataServiceToken As New MetadataService.CrmAuthenticationToken()
    metadataServiceToken.AuthenticationType = Microsoft.Crm.Sdk.AuthenticationType.AD
    metadataServiceToken.OrganizationName = OrganizationName

    Dim credentials As ICredentials = New NetworkCredential(Username, Password, Domain)

    _service = New CrmService.CrmService()
    _service.Url = CRMServiceUrl
    _service.CrmAuthenticationTokenValue = crmServiceToken
    _service.Credentials = credentials

    _metadataService = New MetadataService.MetadataService()
    _metadataService.Url = MetadataServiceUrl
    _metadataService.CrmAuthenticationTokenValue = metadataServiceToken
    _metadataService.Credentials = credentials
End Sub

以及获取联系人的方法

Public Function GetContact(ByVal request As GetContactRequest) As contact Implements ICRM.GetContact
    Dim query As New QueryExpression()
    query.EntityName = EntityName.contact.ToString()
    query.ColumnSet = New AllColumns()

    Dim condition As ConditionExpression
    Dim expr As New List(Of ConditionExpression)

    condition = New ConditionExpression()
    condition.AttributeName = "statecode"
    condition.[Operator] = ConditionOperator.Equal
    condition.Values = New Object() {0}
    expr.Add(condition)

    If request.ContactId <> Guid.Empty Then
        condition = New ConditionExpression()
        condition.AttributeName = "contactid"
        condition.[Operator] = ConditionOperator.Equal
        condition.Values = New String() {request.ContactId.ToString}
        expr.Add(condition)
    End If
    If Not String.IsNullOrEmpty(request.CustomerCode) Then
        condition = New ConditionExpression()
        condition.AttributeName = "new_orgcustomerno"
        condition.[Operator] = ConditionOperator.Like
        condition.Values = New String() {request.CustomerCode + "%"}
        expr.Add(condition)
    End If

    If Not String.IsNullOrEmpty(request.ContactSeq) Then
        condition = New ConditionExpression()
        condition.AttributeName = "new_contact_seq"
        condition.[Operator] = ConditionOperator.Like
        condition.Values = New String() {request.ContactSeq + "%"}
        expr.Add(condition)
    End If


    Dim filter As New FilterExpression()
    filter.FilterOperator = LogicalOperator.[And]
    filter.Conditions = expr.ToArray

    query.Criteria = filter
    Dim contacts As BusinessEntityCollection = _service.RetrieveMultiple(query)

    If contacts.BusinessEntities.Length > 0 Then
        Dim a As contact = DirectCast(contacts.BusinessEntities(0), contact)
        Return a
    Else
        Return Nothing
    End If
End Function
4

2 回答 2

0

这只是一个建议,但我认为它与缓存无关。可能的问题是权限问题或条件问题。我的意思是,如果您在以某个用户身份登录 CRM 时创建了联系人,但尝试在其他 CRM 用户下检索之前创建的联系人。或者可能是您添加到条件列表中的其他列,可能其中的一些列没有您认为存在的值。

于 2012-06-13T14:54:18.167 回答
0

已解决:通过使用 Retrieve() 而不是 RetrieveMultiple() 我立即获得了联系。

这意味着通过其他列搜索新创建的联系人,我无法立即访问它(必须等待几分钟)。我必须使用contactid。

于 2012-07-03T07:13:51.407 回答