crmservice.asmxを使用してDynamicsCRM4から連絡先を取得するカスタムアプリがあります。
問題:カスタムアプリで連絡先を検索しましたが、見つかりません。MSCRMにアクセスして、連絡先を作成します。その後、カスタムアプリでもう一度検索しようとしても、連絡先が見つかりません。
10分後に試してみると、連絡先がカスタムアプリにあるため、crmservice.asmxのキャッシュである必要があります。
しかし、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