Articles, News and Opinions on Dynamics AX and related subjects<o:p></o:p>
Click here for screenshot or copy the code below: namespace AXCloud { [DataContract] [DataServiceKey(new[] { "PartitionKey", "RowKey" })] public class ItemData { [DataMember] public string RowKey { get; set; } [DataMember] public String Name { get; set; } [DataMember] public string PartitionKey { get; set; } [DataMember] public DateTime Timestamp { get; set; } public ItemData() { PartitionKey = "AX"; Timestamp = DateTime.Now; } public ItemData(string partitionKey, string rowKey) { PartitionKey = partitionKey; RowKey = rowKey; } } }
namespace AXCloud { [DataContract] [DataServiceKey(new[] { "PartitionKey", "RowKey" })] public class ItemData { [DataMember] public string RowKey { get; set; } [DataMember] public String Name { get; set; } [DataMember] public string PartitionKey { get; set; } [DataMember] public DateTime Timestamp { get; set; } public ItemData() { PartitionKey = "AX"; Timestamp = DateTime.Now; } public ItemData(string partitionKey, string rowKey) { PartitionKey = partitionKey; RowKey = rowKey; } } }
Click here for screenshot or copy the code below: public class ItemDataServiceContext : TableServiceContext { public ItemDataServiceContext(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials) { } public IQueryable Items { get { return this.CreateQuery("Items"); } } public void AddItem(string itemId, string name) { ItemData item = new ItemData(); item.RowKey = itemId; item.Name = name; this.AddObject("Items", item); this.SaveChanges(); } }
public class ItemDataServiceContext : TableServiceContext { public ItemDataServiceContext(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials) { } public IQueryable Items { get { return this.CreateQuery("Items"); } } public void AddItem(string itemId, string name) { ItemData item = new ItemData(); item.RowKey = itemId; item.Name = name; this.AddObject("Items", item); this.SaveChanges(); } }
Click here for a full screenshot or copy the below code to add before the return statement: CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) => { var connectionString = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName); configSettingPublisher(connectionString); } ); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); storageAccount.CreateCloudTableClient().CreateTableIfNotExist("Items");
CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) => { var connectionString = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName); configSettingPublisher(connectionString); } ); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); storageAccount.CreateCloudTableClient().CreateTableIfNotExist("Items");
Click here for a full screenshot or copy the code below: public void AddItem(ItemData item) { CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) => { var connectionString = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName); configSettingPublisher(connectionString); }); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); new ItemDataServiceContext(storageAccount.TableEndpoint.ToString(), storageAccount.Credentials).AddItem(item.RowKey, item.Name); }
public void AddItem(ItemData item) { CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) => { var connectionString = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName); configSettingPublisher(connectionString); }); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); new ItemDataServiceContext(storageAccount.TableEndpoint.ToString(), storageAccount.Credentials).AddItem(item.RowKey, item.Name); }
Click here for full screenshot of the class. public static void InventTableInsertHandler(XppPrePostArgs args) { InventTable inventTable = new InventTable((Microsoft.Dynamics.AX.ManagedInterop.Record)args.getThis()); AzureItems.ItemData itemData = new AzureItems.ItemData(); itemData.RowKey = inventTable.ItemId; itemData.Name = inventTable.NameAlias; System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding_IService1"; System.ServiceModel.EndpointAddress address = new System.ServiceModel.EndpointAddress("http://127.0.0.1:83/Service1.svc"); AzureItems.Service1Client client = new AzureItems.Service1Client(binding, address); client.AddItem(itemData); }
public static void InventTableInsertHandler(XppPrePostArgs args) { InventTable inventTable = new InventTable((Microsoft.Dynamics.AX.ManagedInterop.Record)args.getThis()); AzureItems.ItemData itemData = new AzureItems.ItemData(); itemData.RowKey = inventTable.ItemId; itemData.Name = inventTable.NameAlias; System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding(); binding.Name = "BasicHttpBinding_IService1"; System.ServiceModel.EndpointAddress address = new System.ServiceModel.EndpointAddress("http://127.0.0.1:83/Service1.svc"); AzureItems.Service1Client client = new AzureItems.Service1Client(binding, address); client.AddItem(itemData); }