加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

CRM WebService 域验证 获取service

发布时间:2020-12-16 22:50:27 所属栏目:安全 来源:网络整理
导读:今天折磨了一小天总算把问题解决了,首先描述一下问题。 1,写CRM2011 的webService接口,在查询数据的时候需要进行权限控制。 首先想到的办法是用CRM中标准的 IOrganizationService 对象,但是常规的方法中必须要知道登录的用户名,密码才能生成对象。 但实际

今天折磨了一小天总算把问题解决了,首先描述一下问题。
1,写CRM2011 的webService接口,在查询数据的时候需要进行权限控制。
首先想到的办法是用CRM中标准的 IOrganizationService 对象,但是常规的方法中必须要知道登录的用户名,密码才能生成对象。
但实际情况是访问webService是域认证的方式不能取得密码,所以不能通过用户名密码的方式生成该对象。
但是SDK中其实还提供了一种方式只不过是我们不常用而已:通过用户凭证生成 IOrganizationService 对象。
这样的话问题就解决了。因为在域认证的情况下我们可以获得他的域凭证。
闲话少说上代码:

[WebMethod]
        public int getService()
        {

            Uri orgServiceUri = new Uri("http://localhost:5555/orgName/XRMServices/2011/Organization.svc");
            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
            OrganizationServiceProxy crmServiceProxy = new OrganizationServiceProxy(orgServiceUri,null,credentials,null);
            IOrganizationService crmService = (IOrganizationService)crmServiceProxy;
            //crmService.Delete("contact",new Guid("B53FA2A9-76CB-E411-8BE6-B82A72D5A332"));


            String fetchXml = @"<fetch mapping=""logical"" count=""50"" version=""1.0""> <entity name=""contact""> <attribute name=""address1_telephone1"" /> <attribute name=""contactid"" /> <attribute name=""firstname"" /> <attribute name=""lastname"" /> </entity> </fetch>";

            // Build fetch request and obtain results.
            RetrieveMultipleRequest efr = new RetrieveMultipleRequest()
            {
                Query = new FetchExpression(fetchXml)
            };

            EntityCollection entityResults = ((RetrieveMultipleResponse)crmService.Execute(efr)).EntityCollection;

            int count = 0;
            count = entityResults.Entities.Count;


            return count;

        }

换两个有不同角色的用户调用该方法,返回的值如下:

这里写图片描述


这里写图片描述

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读