1

第一篇文章,所以请善待。

我正在尝试返回用户在 Dynamics 365 (Online) 中有权访问的组织列表。

这个函数大约有 50% 的时间工作,它可以很好地进行身份验证,并返回 org 列表,但随机它根本不会返回任何 orgs。

我使用的是 XXX@XXX.onmicrosoft.com 格式的登录,访问动态 365 本身就可以了。

我已经有了组织端点,可以很好地创建组织服务,只是努力从函数中获得一致的结果。

我已经调查了服务上的任何最大调用尝试次数,使用 fiddler 来跟踪请求和响应以寻找任何线索,但到目前为止还没有,也没有错误。

任何帮助将不胜感激

Public Shared Function retrieveOrganizations(conn As Connectiondata) As List(Of orgDetails)

    ' New Org List
    Dim orgList As New List(Of orgDetails)

    ' Accepts all certs
    ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(Function() True)

    ' Create a management service
    Dim serviceManagement As IServiceManagement(Of IDiscoveryService) = ServiceConfigurationFactory.CreateManagement(Of IDiscoveryService)(New Uri("https://disco.crm11.dynamics.com/XRMServices/2011/Discovery.svc"))

    ' Find what type of endpoint we need to use
    Dim endpointType As AuthenticationProviderType = serviceManagement.AuthenticationType

    ' Set the credentials based on the auth type and conn details
    Dim authCredentials As AuthenticationCredentials = GetCredentials(serviceManagement, endpointType, conn)

    'Create discovery service proxy
    Dim discoService As New DiscoveryServiceProxy(serviceManagement, authCredentials.ClientCredentials)

    ' Authenticate the service
    discoService.Authenticate()

    'Retrieve Organization details
    Dim orgRequest As New RetrieveOrganizationsRequest()

    ' Cast the response
    Dim allOrgs As RetrieveOrganizationsResponse = DirectCast(discoService.Execute(orgRequest), RetrieveOrganizationsResponse)

    'Print all organization(s)(instances) endpoint.
    For Each orgdetail As OrganizationDetail In allOrgs.Details

        ' Create a new object
        orgList.Add(New orgDetails With {.friendlyName = orgdetail.FriendlyName, .ID = orgdetail.OrganizationId.ToString})

    Next

    ' Return the list
    Return orgList

End Function
4

0 回答 0