导航

CRM 2016 Get IOrganizationService

Posted on 2018-11-19 10:17  yiyishuitian  阅读(273)  评论(0编辑  收藏  举报

得到域认证下的IOrganizationService

    private IOrganizationService GetOrgService()
    {

        Uri orgServiceUri = new Uri("http://xxxx: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;

        return crmService;
    }


使用 用户名密码方式下的IOrganizationService

    private IOrganizationService GetOrgService()
    {

                Uri orgServiceUri = new Uri("http://xxxx:5555/orgname/XrmServices/2011/Organization.svc");
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
                OrganizationServiceProxy proxy = new OrganizationServiceProxy(orgServiceUri, null, clientCredentials, null);
                service = (IOrganizationService)proxy;

        return service ;
    }