1

MS Dynamics 2011 Online に接続しようとしています。コードの xrm の使用部分で、次のエラーが表示されます。

値 'Xrm.XrmServiceContext, Xrm' は有効な型として認識されないか、型 'Microsoft.Xrm.Sdk.Client.OrganizationServiceContext' ではありません。

これが私のコードです:

        var contextName = "Xrm";
        using (var xrm = CrmConfigurationManager.CreateContext(contextName) as XrmServiceContext)
        {


            WriteExampleContacts(xrm);

            //Create a new contact called Allison Brown.
            var allisonBrown = new Xrm.Contact
            {
                FirstName = "Allison",
                LastName = "Brown",
                Address1_Line1 = "23 Market St.",
                Address1_City = "Sammamish",
                Address1_StateOrProvince = "MT",
                Address1_PostalCode = "99999",
                Telephone1 = "12345678",
                EMailAddress1 = "allison.brown@example.com"
            };

            xrm.AddObject(allisonBrown);
            xrm.SaveChanges();

            WriteExampleContacts(xrm);
        }

App.config:

  <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  <section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
  </configSections>

  <connectionStrings>
    <add name="Xrm"     
connectionString="Url=https://MYORG.crm.dynamics.com/XRMServices"/>
  </connectionStrings>

<microsoft.xrm.client>
<contexts>
  <add name="Xrm" type="Xrm.XrmServiceContext, Xrm"/>
</contexts>
</microsoft.xrm.client>
</configuration>

Xrm.XrmServiceContext は、私の実際の XrmServiceContext 名です。コンソール アプリケーションの Xrm.cs ファイルに保持されます。

4

1 に答える 1

2

簡易接続を使用するだけです。

参照する必要がありMicrosoft.Xrm.Sdk.ClientMicrosoft.Xrm.Client.Services

CrmConnection crmConnection = CrmConnection.Parse("Url=https://XXX.crm4.dynamics.com; Username=user@domain.onmicrosoft.com; Password=passwordhere; DeviceID=contoso-ba9f6b7b2e6d; DevicePassword=passcode;");
OrganizationService service = new OrganizationService(crmConnection);

XrmServiceContext context = new XrmServiceContext(service);

var allisonBrown = new Xrm.Contact
            {
                FirstName = "Allison",
                LastName = "Brown",
                Address1_Line1 = "23 Market St.",
                Address1_City = "Sammamish",
                Address1_StateOrProvince = "MT",
                Address1_PostalCode = "99999",
                Telephone1 = "12345678",
                EMailAddress1 = "allison.brown@example.com"
            };

context.AddObject(allisonBrown);
context.SaveChanges();
于 2013-05-10T20:54:57.743 に答える