通过Web服务创建实体随机失败,出现0x80048405(访问被拒绝) [英] Creating entities through web services fails randomly with 0x80048405 (Access is denied)

查看:116
本文介绍了通过Web服务创建实体随机失败,出现0x80048405(访问被拒绝)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个公共的ASP.NET Web UI,它用作基础CRM4实例的有限前端。通过CRM4 SDK Web服务实现通信:

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;

使用xml查询调用获取总是成功,但是有时实体创建失败:

Calling fetch with xml query always succeeds, but entity creation fails sometimes:

var entity = new DynamicEntity("some_entity");
var resultGuid = service.Create(entity);

iisreset创建之后总是失败。 IIS日志对CRMservice发出两个POST请求:

After iisreset creation always fails. IIS log says two POST requests to CRMservice:


  1. 没有用户,HTTP 401.5

  2. 域/用户,HTTP 500.0

返回的异常为:

[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详细信息:

Soapexception details:

<detail><error>
  <code>0x80048405</code>
  <description>Access is denied.</description>
  <type>Platform</type>
</error></detail>

当任何人使用CRM自己的UI手动创建some_entity时,事情就会变得很奇怪。之后,Web服务访问将毫无问题。

Things get weird weird when anyone creates some_entity by hand using CRM's own UI. After that web service access works without problems.

更多说明:


  1. 删除或CRM自己的用户界面中的更新无法修复Web服务访问

  2. CRM应用程序池最多使用1个工作进程。

  3. 一段时间后,Web服务再次中断访问被拒绝(可能回收wp)

  4. 错误不取决于数据。

  5. 删除PreAuthenticate并没有任何改变。

  6. 在事件日志中没有用。

  1. deletion or update in CRM's own UI does NOT fix web service access
  2. CRM apppool uses max 1 worker process.
  3. After a while web service breaks again to the "access denied" (probably recycling wp)
  4. Errors do NOT depend on data.
  5. removing PreAuthenticate didn't change anything.
  6. Nothing useful in event log.

有人可以帮助我摆脱奇怪的拒绝访问错误吗?为什么触摸CRM UI会更改Web服务行为?

Could anyone help me get rid of that weird access denied error? Why touching CRM UI changes web service behavior?

编辑:
尽管Michael M提供了解决该错误的方法,但我仍然不明白为什么/如何做CRM UI是否会影响CrmService身份验证?

Even though Michael M provided a workaround for the error, I still don't understand why/how does CRM UI affect CrmService authentication.

推荐答案

您的令牌可能不正确。根据您的身份验证类型,您可能还需要更改令牌的AuthenticationType。尝试以下方法获取服务实例。

It's possible that your token is not correct. Depending on your authentication type, you may also need to change the token's AuthenticationType. Try the following method to get an instance of the service.

private static CrmService GetService(string organization, string server, string domain,
                     string username, string password)
    {
        server = server.TrimEnd(new[] {'/'});

        // Initialize an instance of the CrmDiscoveryService Web service proxy.
        var disco
            = new CrmDiscoveryService
                {
                    Url = String.Format("{0}/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx", server)
                };

        //Retrieve a list of available organizations.
        var orgResponse =
            (RetrieveOrganizationsResponse) disco.Execute(
                new RetrieveOrganizationsRequest
                    {
                        UserId = domain + "\\" + username,
                        Password = password
                    });

        //Find the desired organization.
        foreach (var orgDetail in orgResponse.OrganizationDetails)
        {
            if (orgDetail.OrganizationName != organization)
                continue;

            //Retrieve the ticket.
            var ticketResponse =
                (RetrieveCrmTicketResponse) disco.Execute(
                    new RetrieveCrmTicketRequest
                        {
                            OrganizationName = organization,
                            UserId = domain + "\\" + username,
                            Password = password
                        });

            //Create the CrmService Web service proxy.
            var token = new CrmAuthenticationToken
                {
                    AuthenticationType = 2,
                    OrganizationName = organization,
                    CrmTicket = ticketResponse.CrmTicket
                };

            return new CrmService
                {
                    CrmAuthenticationTokenValue = token,
                    Url = orgDetail.CrmServiceUrl
                };
        }
        return null;
    }

这篇关于通过Web服务创建实体随机失败,出现0x80048405(访问被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆