Answered by:
Create user using CRM 2011 wcf services

Question
-
I've used the following code in a C# console application to create a user under the default organization TestOrg1. Now the user is created but when I browse to this organization using the url ... http://myservername:5555/testorg1/main.aspx it sowing that the "Specified Organization is disabled". On the deployment Manager I can see the organization state is "Enabled".Prior to adding this user there were no such issues.
I'm using CRM 2011 On-premises deployment and frond-end,back-end,deplyment and database server are on separate machines . the code I used is the following :
const string BusinessUnitEntityName = "businessunit";
const string BusinessUnitIdColumnName = "businessunitid";
const string ParentBusinessUnitIdColumnName = "parentbusinessunitid";
const string SystemUserEntityName = "systemuser";
const string FirstNameColumnName = "firstname";
const string DomainNameColumnName = "domainname";
const string LastNameColumnName = "lastname";
const string IncomingEmailDeliveryMethod = "incomingemaildeliverymethod";
const string OutgoingEmailDeliveryMethod = "outgoingemaildeliverymethod";
const string PersonalEmailAddress = "personalemailaddress";
const string InternalEmailAddress = "internalemailaddress";
string organizationUrl = string.Empty;
Guid userId = Guid.Empty;
// use the discovery service to obtain the IOrganizationService endpoint for
// the specificed organization.
Uri serviceUri = new Uri("http://192.168.1.37:5555/XRMServices/2011/Discovery.svc");
IServiceConfiguration<IDiscoveryService> serviceConfig
= ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(serviceUri);
// use the credentials of the current user
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential(CRMAdminUser, CRMAdminUserPassword, CRMServerDomain);
// Connect to the Discovery service.
// The using statement assures that the service proxy will be properly disposed.
using (DiscoveryServiceProxy proxy = new DiscoveryServiceProxy(serviceConfig, credentials))
{
// Retrieve details about a single organization discoverable via the
// Discovery service.
RetrieveOrganizationRequest request = new RetrieveOrganizationRequest
{
UniqueName = "TestOrg1",
AccessType = EndpointAccessType.Default,
Release = OrganizationRelease.Current
};
// Execute the request
RetrieveOrganizationResponse response = (RetrieveOrganizationResponse)proxy.Execute(request);
// retrieve the IOrganizationService Uri
organizationUrl = response.Detail.Endpoints[EndpointType.OrganizationService];
//organizationUrl = "http://192.168.1.37:5555/TestOrg1/XRMServices/2011/Organization.svc";
}
// use URL obtained by the discovery service to connect to the IOrganizationService endpoint
Uri organizationUri = new Uri(organizationUrl);
IServiceConfiguration<IOrganizationService> orgServiceConfig
= ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUri);
// The using statement assures that the service proxy will be properly disposed.
using (OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(orgServiceConfig, credentials))
{
//orgProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
//orgProxy.Authenticate();
// Retrieve the default business unit needed to create the user.
QueryExpression businessUnitQuery = new QueryExpression
{
EntityName = BusinessUnitEntityName,
ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(BusinessUnitIdColumnName),
Criteria =
{
Conditions =
{
new ConditionExpression(ParentBusinessUnitIdColumnName,
ConditionOperator.Null)
}
}
};
// Get the business unit id from the returned entity
EntityCollection entities = orgProxy.RetrieveMultiple(businessUnitQuery);
Guid defaultBusinessUnitId = entities[0].Id;
//Populate an entity with data for a new system user.
Entity entity = new Entity(SystemUserEntityName);
entity.Attributes.Add(DomainNameColumnName, "crm\\tuser2");
entity.Attributes.Add(FirstNameColumnName, "tuser2");
entity.Attributes.Add(LastNameColumnName, "De");
entity.Attributes.Add(IncomingEmailDeliveryMethod, new OptionSetValue(inEmailAccType));
entity.Attributes.Add(OutgoingEmailDeliveryMethod, new OptionSetValue(outEmailAccType));
entity.Attributes.Add(PersonalEmailAddress, "rrr@yahoo.co.in");
entity.Attributes.Add(InternalEmailAddress, "rrr@rediffmail.com");
entity.Attributes.Add(BusinessUnitIdColumnName, new EntityReference
{
Id = defaultBusinessUnitId,
Name = BusinessUnitEntityName,
LogicalName = BusinessUnitEntityName
});
userId = orgProxy.Create(entity);
}
Monday, August 29, 2011 10:08 AM
Answers
-
I think this thread should help - http://social.microsoft.com/Forums/en/crm/thread/9399069a-8b7c-4bbe-ae5a-972faa0f007c
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/- Proposed as answer by Blake ScarlavaiMVP Wednesday, August 31, 2011 11:37 AM
- Marked as answer by Michael T. SnyderModerator Saturday, September 17, 2011 1:13 PM
Tuesday, August 30, 2011 1:31 PM
All replies
-
Did you mean that you created a systemuser whose name is "tuser2" , logging the crm system with "tuser2", and then the crm system promt you that the specified organization is disabled?
did you assign any role to the "tuser2"?
daemon linMonday, August 29, 2011 12:28 PM -
Thanks for your reply
I added the user account "tuser2" to the Tenant Organization "TestOrg1" which is the default organization now when i try to browse the link http://myservername:5555/testorg1/main.aspx , I get the message that the specified Organization is disabled. See the screen shot below.
I've not assigned any role to the "tuser2"
Monday, August 29, 2011 12:49 PM -
Have you customized the area with the error at all or is that native?
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/Tuesday, August 30, 2011 4:54 AM -
Any ideas on this? Also I've used the code included in the document "Microsoft Dynamics CRM 2011 Service Provider Planning and Deployment Guide" to create an organization. The organization is created successfully but in the deployment manager it's state is showing as "Pending".
Tuesday, August 30, 2011 4:57 AM -
I don't think it is your console app code. I think something is wrong with the 'Visor' area where your error is. I would run Fiddler while browsing to the main.aspx page and see what url is failing.
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/Tuesday, August 30, 2011 5:07 AM -
Thanks for your reply. I'm going to try this.Tuesday, August 30, 2011 5:10 AM
-
I did run Fiddler while browsing to the main.aspx page and could see couple of HTTP 401 responses they are :
POST http://192.168.1.37:5555/TestOrg1/AppWebServices/MessageBar.asmx
401 Unauthorized (text/html)
GET http://192.168.1.37:5555/TestOrg1/_controls/ribbon/RibbonLayout.js.aspx?hierarchy=00000000-0000-0000-0000-000000000000&id=EntityTemplateTab.activitypointer.NoRelationship.SubGridStandard.Mscrm.SubGrid.activitypointer.MainTab&ise=1&lcid=1033&mver=562305670&oc=0&rver=736893761&ver=1716711896
401 Unauthorized (text/plain)Also on the CRM front-end server on the application event log I found the following warning
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 8/30/2011 11:12:27 AM
Event time (UTC): 8/30/2011 5:42:27 AM
Event ID: db961ab222d542e998de17989c3b99b4
Event sequence: 741
Event occurrence: 12
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/2/ROOT-1-129590894870731138
Trust level: Full
Application Virtual Path: /
Application Path: C:\Program Files\Microsoft Dynamics CRM\CRMWeb\
Machine name: CRM2011FE1
Process information:
Process ID: 1260
Process name: w3wp.exe
Account name: CRM\CRMAPPSVC
Exception information:
Exception type: CrmException
Exception message: The CRM organization you are attempting to access is currently disabled. Please contact your system administrator
at Microsoft.Crm.BusinessEntities.SecurityLibrary.ValidateOrganizationState(IOrganizationContext context)
at Microsoft.Crm.BusinessEntities.SecurityLibrary.GetUserInfoCommon(IOrganizationContext context, Guid userGuid)
at Microsoft.Crm.BusinessEntities.SecurityLibrary.GetCallerAndBusinessGuidsFromThread(WindowsIdentity identity, Guid organizationId)
at Microsoft.Crm.Authentication.CrmWindowsIdentity..ctor(WindowsIdentity innerIdentity, Boolean publishCrmUser, Guid organizationId)
at Microsoft.Crm.Authentication.WindowsAuthenticationProviderBase.Authenticate(HttpApplication application, WindowsIdentity userIdentity)
at Microsoft.Crm.Authentication.AuthenticationStep.Authenticate(HttpApplication application)
at Microsoft.Crm.Authentication.AuthenticationPipeline.Authenticate(HttpApplication application)
at Microsoft.Crm.Authentication.AuthenticationEngine.Execute(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Request information:
Request URL: http://localhost:5555/Tools/InPageHelpProxy/InPageHelpProxy.aspx?sitemappath=Workplace|MyWork|nav_dashboards
Request path: /Tools/InPageHelpProxy/InPageHelpProxy.aspx
User host address: ::1
User: CRM\Administrator
Is authenticated: True
Authentication Type: Negotiate
Thread account name: CRM\CRMAPPSVC
Thread information:
Thread ID: 25
Thread account name: CRM\CRMAPPSVC
Is impersonating: True
Stack trace: at Microsoft.Crm.BusinessEntities.SecurityLibrary.ValidateOrganizationState(IOrganizationContext context)
at Microsoft.Crm.BusinessEntities.SecurityLibrary.GetUserInfoCommon(IOrganizationContext context, Guid userGuid)
at Microsoft.Crm.BusinessEntities.SecurityLibrary.GetCallerAndBusinessGuidsFromThread(WindowsIdentity identity, Guid organizationId)
at Microsoft.Crm.Authentication.CrmWindowsIdentity..ctor(WindowsIdentity innerIdentity, Boolean publishCrmUser, Guid organizationId)
at Microsoft.Crm.Authentication.WindowsAuthenticationProviderBase.Authenticate(HttpApplication application, WindowsIdentity userIdentity)
at Microsoft.Crm.Authentication.AuthenticationStep.Authenticate(HttpApplication application)
at Microsoft.Crm.Authentication.AuthenticationPipeline.Authenticate(HttpApplication application)
at Microsoft.Crm.Authentication.AuthenticationEngine.Execute(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)Now all the organizations when browsed for the main.aspx page is showing the same nagging message "The specified organization is disabled" just above the Dashboard.
Users can still be created and organization and user information can be retrieved and on the Deployment manager the organization status is "Enabled".
Any ideas. I'm stuck here.
Tuesday, August 30, 2011 6:24 AM -
No I have not customized the area with the error its still the native one
Tuesday, August 30, 2011 7:56 AM -
I think this thread should help - http://social.microsoft.com/Forums/en/crm/thread/9399069a-8b7c-4bbe-ae5a-972faa0f007c
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/- Proposed as answer by Blake ScarlavaiMVP Wednesday, August 31, 2011 11:37 AM
- Marked as answer by Michael T. SnyderModerator Saturday, September 17, 2011 1:13 PM
Tuesday, August 30, 2011 1:31 PM -
thanks a lot . The above thread helped me in solving the problem.
Wednesday, August 31, 2011 5:17 AM