我有一个自定义应用程序,它使用 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