Microsoft Dynamics 365获取组织列表时遇organizationName异常求助
Hey there, let's work through the organizationName-related DiscoveryServiceFault you're hitting when running your organization retrieval code. First, here's the code you're using for reference:
var clientCredentials = new ClientCredentials(); clientCredentials.Windows.ClientCredential.Domain = "domain"; clientCredentials.Windows.ClientCredential.UserName = "user"; clientCredentials.Windows.ClientCredential.Password = "password"; var discoveryUri = new Uri(String.Format("http://{0}/XRMServices/2011/Discovery.svc", "10.20.30.40")); var discoveryServiceProxy = new DiscoveryServiceProxy(discoveryUri, null, clientCredentials, null); discoveryServiceProxy.Authenticate(); var retrieveOrganizationResponse = (RetrieveOrganizationsResponse)discoveryServiceProxy.Execute(new RetrieveOrganizationRequest());
Here are the most common fixes for this issue:
1. Add Explicit Filters to Your RetrieveOrganizationRequest
The default empty RetrieveOrganizationRequest might not play nicely with your environment's configuration. Try adding specific parameters to clarify what you're requesting:
var orgRequest = new RetrieveOrganizationRequest { // Request the current release version of organizations Release = OrganizationRelease.Current, // Use default access type AccessType = EndpointAccessType.Default, // Optional: If you know the exact org name, uncomment this line // OrganizationName = "YourTargetOrganization" }; var retrieveOrganizationResponse = (RetrieveOrganizationsResponse)discoveryServiceProxy.Execute(orgRequest);
2. Validate Authentication & Permissions
Even though you're calling Authenticate(), there might be permission gaps or proxy initialization issues:
- Make sure the user account you're using has the Discovery Service Access privilege in Dynamics 365. You can check this in the Dynamics Admin Center under Security > Users > [Your User] > Security Roles.
- Wrap the proxy in a
usingblock to ensure proper resource disposal, which often resolves flaky connection issues:
using (var discoveryServiceProxy = new DiscoveryServiceProxy(discoveryUri, null, clientCredentials, null)) { discoveryServiceProxy.Authenticate(); var orgRequest = new RetrieveOrganizationRequest(); var retrieveOrganizationResponse = (RetrieveOrganizationsResponse)discoveryServiceProxy.Execute(orgRequest); }
3. Verify Your Discovery Service URI
Double-check that your URI is correct and reachable:
- For on-premises instances, confirm
10.20.30.40is accessible from your machine, and that navigating tohttp://10.20.30.40/XRMServices/2011/Discovery.svcin a browser loads the WSDL page (you'll need to log in with the same domain/password you're using in code). - If you're targeting an online environment, the URI should follow the format
https://disco.crm[region].dynamics.com/XRMServices/2011/Discovery.svc(adjust the region code as needed).
4. Check SDK and Server Version Compatibility
Mismatched versions between your Dynamics 365 SDK assemblies and the on-premises server can trigger unexpected faults. Ensure the SDK version you're referencing in your project matches the version of your Dynamics 365 server exactly.
内容的提问来源于stack exchange,提问作者Raul Mercado

