I also have a very similar problem and it occurs when running from my webapi 2 project and in the cloud on my webapp
I create the client like so
var serviceClient = new CrmServiceClient(AuthType=Office365;Username=<USER_NAME>; Password=<PASSWORD>;Url=https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc);
Often I have the following properties on the client once instantiated, that means I get a null ref exception when I try to use the client
IsReady = false
+ OrganizationServiceProxy null Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy
+ OrganizationWebProxyClient null Microsoft.Xrm.Sdk.WebServiceClient.OrganizationWebProxyClient
LastCrmError "Unable to Login to Dynamics CRMOrganizationServiceProxy is nullOrganizationServiceProxy is nullOrganizationServiceProxy is nullOrganizationServiceProxy is nullOrganizationServiceProxy is null" string
I found this article that helps me connect in Azure blog.vertica.dk/.../crm-2016-unable-to-login-to-dynamics-crm , but I still have the same problem in my local webapi app unless I stop my iis express process then I can SOMETIMES connect once then on the second request IsReady is false etc.
The article says to set create the following app setting in Azure WEBSITE_LOAD_USER_PROFILE = 1 (true), and thats working for me
Locally in my webapi app I have edited my .vs\config\applicationhost.config so that my app pool has the same setting i.e. <processModel loadUserProfile="true" />
If I could get some help to be able to connect consistently in my local project it would be great
Example
Request sent from POSTMAN in my browser to webapi 2 project on my machine, connecting to CRM 2016 online
TRACE LOG for failed attempt.
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : DiscoveryServer indicated organization service location = https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Organization Service URI is = https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : ConnectAndInitCrmOrgService - Initializing Organization Service Object
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : ConnectAndInitCrmOrgService - Requesting connection to Org with CRM Version: 8.1.0.359
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : ConnectAndInitCrmOrgService - Using ISerivceManagement
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : ConnectAndInitCrmOrgService - attempting to connect to CRM server @ https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.RemoteDependency","time":"2016-06-04T13:03:03.3822979+00:00","tags":{"ai.device.roleInstance":"<MY_PC>","ai.application.ver":"Unknown","ai.device.type":"PC","ai.device.id":"<MY_PC>","ai.device.oemName":"VMware, Inc.","ai.device.model":"VMware Virtual Platform","ai.device.network":"Ethernet","ai.device.language":"en-GB","ai.user.userAgent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36","ai.operation.name":"GET optionsets","ai.operation.id":"<REMOVED>","ai.internal.sdkVersion":"1.2.3.490"},"data":{"baseType":"RemoteDependencyData","baseData":{"ver":2,"name":"https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc?wsdl&sdkversion=8.1","kind":1,"value":<REMOVED>,"dependencyKind":1,"success":true,"async":false,"dependencySource":0,"properties":{"DeveloperMode":"true"}}}}
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.RemoteDependency","time":"2016-06-04T13:03:03.6102748+00:00","tags":{"ai.device.roleInstance":"<MY_PC>","ai.application.ver":"Unknown","ai.device.type":"PC","ai.device.id":"<MY_PC>","ai.device.oemName":"VMware, Inc.","ai.device.model":"VMware Virtual Platform","ai.device.network":"Ethernet","ai.device.language":"en-GB","ai.user.userAgent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36","ai.operation.name":"GET optionsets","ai.operation.id":"<REMOVED>","ai.internal.sdkVersion":"1.2.3.490"},"data":{"baseType":"RemoteDependencyData","baseData":{"ver":2,"name":"https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc?wsdl=wsdl0","kind":1,"value":<REMOVED>,"dependencyKind":1,"success":true,"async":false,"dependencySource":0,"properties":{"DeveloperMode":"true"}}}}
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : ConnectAndInitCrmOrgService - created CRM server proxy configuration for https://<HOSTNAME>.api.crm4.dynamics.com/XRMServices/2011/Organization.svc - duration: 00:00:00.4700699
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : ConnectAndInitCrmOrgService - proxy requiring authentication type : OnlineFederation
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Source : Microsoft.Xrm.Sdk
Method : Assert
Date : 04/06/2016
Time : 14:03:03
Error : clientCredentials.UserName.UserName or clientCredentials.Windows.ClientCredential.UserName MUST be populated!
Stack Trace : at Microsoft.Xrm.Sdk.ClientExceptionHelper.Assert(Boolean condition, String message)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.GetIdentityProvider(ClientCredentials clientCredentials)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateOnlineFederationInternal(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Authenticate(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.Authenticate(AuthenticationCredentials authenticationCredentials)
at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.ClaimsIFDFailOverAuth[T](IServiceManagement`1 servicecfg, Uri homeRealm, ClientCredentials userCredentials, ClientCredentials deviceCredentials, Int32 depthLevel, Boolean tryNetworkCred)
at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.CreateAndAuthenticateProxy[T](IServiceManagement`1 servicecfg, Uri ServiceUri, Uri homeRealm, ClientCredentials userCredentials, ClientCredentials deviceCredentials, String LogString)
at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.ConnectAndInitCrmOrgService(OrganizationDetail orgdata, Boolean IsOnPrem, Uri homeRealmUri)
at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.InitCRM2011Service()
======================================================================================================================
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM
'iisexpress.exe' (CLR v4.0.30319: <REMOVED>): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\<REMOVED>\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null