We have a public ASP.NET web UI which is used as limited frontend to underlying CRM4 instance. Communication is achieved through CRM4 SDK web service:
var service = new Microsoft.Crm.SdkTypeProxy.CrmService();
service.Credentials = new System.Net.NetworkCredential("user", "pass", "domain");
service.Url = server + "/MSCRMServices/2007/CrmService.asmx";
var token = new CrmAuthenticationToken();
token.OrganizationName = organizationName;
service.CrmAuthenticationTokenValue = token;
service.PreAuthenticate = true;
Calling fetch with xml query always succeeds, but entity creation fails sometimes:
var entity = new DynamicEntity("some_entity");
var resultGuid = service.Create(entity);
After iisreset creation always fails. IIS log says two POST requests to CRMservice:
- no user, HTTP 401.5
- domain/user, HTTP 500.0
Exception returned is :
[SoapException: Server was unable to process request.]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +1769861
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +345
Microsoft.Crm.SdkTypeProxy.CrmService.Create(BusinessEntity entity) +79
Soapexception details:
<detail><error>
<code>0x80048405</code>
<description>Access is denied.</description>
<type>Platform</type>
</error></detail>
Things get weird weird when anyone creates some_entity by hand using CRM's own UI. After that web service access works without problems.
More notes:
- deletion or update in CRM's own UI does NOT fix web service access
- CRM apppool uses max 1 worker process.
- After a while web service breaks again to the "access denied" (probably recycling wp)
- Errors do NOT depend on data.
- removing PreAuthenticate didn't change anything.
- Nothing useful in event log.
Could anyone help me get rid of that weird access denied error? Why touching CRM UI changes web service behavior?
EDIT: Even though Michael M provided a workaround for the error, I still don't understand why/how does CRM UI affect CrmService authentication.