2016-11-11 1 views
3

Ich versuche Ereignisdatensätze aus Dynamic 365 abzurufen, aber während ich versuche, Referenz von OrganizationService zu erstellen, erhalte ich NULL-Referenz.Objektreferenz von OrganizationService erstellt nicht in Micosoft Dynamic 365

Ich weiß nicht, ob etwas in Dynamic 365 neu ist, und ich mache es falsch?

Hinweis: Benutzername und Kennwort werden aus einem bestimmten Grund entfernt. Aber es ist in Code übergeben !!

CrmConnection crmConnectionString = CrmConnection.Parse("Url=https://stbtrial.api.crm8.dynamics.com/XRMServices/2011/Organization.svc;Username=;Password=;"); 


OrganizationService service = new OrganizationService(crmConnectionString); 
QueryExpression query = new QueryExpression("incident") 
        { 
         ColumnSet = new ColumnSet("title", "ticketnumber", "subjectid", "customerid", "caseorigincode", "pcl_pushtocaseflag"), 

         Criteria = 
         { 
          Conditions = 
       { 
        new ConditionExpression 
        { 
         AttributeName="pcl_pushtocaseflag", 
         Operator=ConditionOperator.Equal, 
         Values= { true } 
        } 
       } 
         }, 
         Orders = 
         { 
          new OrderExpression 
          { 
           AttributeName="createdon", 
           OrderType=OrderType.Descending 
          } 
         } 
        }; 
EntityCollection crmCaseRecords = service.RetrieveMultiple(query); 

Antwort

3

Sie können den folgenden Code verwenden.

Verwenden Sie diese Namensräume

using Microsoft.Xrm.Sdk; 

using Microsoft.Xrm.Sdk.Client; 


    #region GetOrganizationService 
public static IOrganizationService GetOrganizationService() 
{ 
    try 
    { 
    IOrganizationService organizationService = null; 

    Uri uri = new Uri("OrganizationUri"); 
    var credentials = new ClientCredentials(); 
    credentials.UserName.UserName = "UserName"; 
    credentials.UserName.Password = "Password"; 

    // Cast the proxy client to the IOrganizationService interface. 
    using (OrganizationServiceProxy organizationServiceProxy = new OrganizationServiceProxy(uri, null, credentials, null)) 
    { organizationService = (IOrganizationService)organizationServiceProxy; } 

    return organizationService; 
    } 
    catch (System.Exception exception) 
    { 
    throw exception; 
    } 
} 
#endregion 

Bitte beachten Sie:

OrganizationUri = https://yourOrgName.api.crm8.dynamics.com/XRMServices/2011/Organization.svc

Username = [email protected]

Verwandte Themen