/// <summary> /// Connect to the instance and create proxy /// </summary> private void SetEloquaServices(ElqService.EloquaServiceClient serviceProxy, EloquaProgramService.ExternalActionServiceClient programServiceProxy) { string strInstanceName = "CSStuartOrmistonE10"; string strUserID = "Prashanth.Govindaiah"; string strUserPassword = "******"; serviceProxy.ClientCredentials.UserName.UserName = strInstanceName + "\\" + strUserID; serviceProxy.ClientCredentials.UserName.Password = strUserPassword; programServiceProxy = new EloquaProgramService.ExternalActionServiceClient(); programServiceProxy.ClientCredentials.UserName.UserName = strInstanceName + "\\" + strUserID; programServiceProxy.ClientCredentials.UserName.Password = strUserPassword; }
/// <summary> /// It reads the contacts from contact entity using some filter /// </summary> private void ReadContacts(List <Product> productCollection, List <ProductInterest> productInt) { const string SearchQuery = "C_DateModified>2013-06-05"; ElqService.EloquaServiceClient ServiceProxy = new ElqService.EloquaServiceClient(); EloquaProgramService.ExternalActionServiceClient ProgramServiceProxy = new EloquaProgramService.ExternalActionServiceClient(); List <ProductOwned> productOwns = new List <ProductOwned>(); ////Perform the authentication this.SetEloquaServices(ServiceProxy, ProgramServiceProxy); EntityType contactEntityType = new EntityType { ID = 0, Name = "Contact", Type = "Base" }; //// Create a new list containing the fields you want populated List <string> fieldList = new List <string>(); // Define a container for the Query results DynamicEntityQueryResults queryResult; //// Set the page number and size for the results const int CurrentPage = 1; const int PageSize = 20; //// If the field list is empty - the request will return all Entity Fields //// Otherwise, only fields defined in the field list are returned if (fieldList.Count == 0) { //// Execute the request and return all of the Entity's fields queryResult = ServiceProxy.Query(contactEntityType, SearchQuery, null, CurrentPage, PageSize); } else { //// Execute the request and return only the selected fields queryResult = ServiceProxy.Query(contactEntityType, SearchQuery, fieldList.ToArray(), CurrentPage, PageSize); } if (queryResult.Entities.Length > 0) { //// Extract each Dynamic Entity in the result foreach (DynamicEntity dynamicEntity in queryResult.Entities) { string[] arrContactValue = new string[4]; ////Extract the field name and value of each field in the collection foreach (KeyValuePair <string, string> field in dynamicEntity.FieldValueCollection) { if (field.Key == "C_EmailAddress") { arrContactValue[0] = field.Value; } if (field.Key == "C_Interested_Product_Id11") { arrContactValue[1] = field.Value; } if (field.Key == "C_Interested_Product_Id21") { arrContactValue[2] = field.Value; } if (field.Key == "C_Interested_Product_Id31") { arrContactValue[3] = field.Value; } } ////Validate if the product interest having some value if (arrContactValue[0] != string.Empty && arrContactValue[1] != null) { productInt = this.ContactProductInterestDetails(arrContactValue[0], arrContactValue[1], arrContactValue[2], arrContactValue[3], dynamicEntity.Id, productCollection, productInt); } } } }
/// <summary> /// It insert the customer product interest details into data card /// </summary> private void InsertDataCard(List <ProductInterest> productInt) { int dataCardId = 0; var dataCardIDs = new int[1]; try { ElqService.EloquaServiceClient ServiceProxy = new ElqService.EloquaServiceClient(); EloquaProgramService.ExternalActionServiceClient ProgramServiceProxy = new EloquaProgramService.ExternalActionServiceClient(); ////Perform the authentication this.SetEloquaServices(ServiceProxy, ProgramServiceProxy); //// Build a DataCardSet Entity Type object - (the ID is the ID of an existing DataCardSet in Eloqua) EntityType entityType = new EntityType { ID = 13, Name = "ProductInterest", Type = "DataCardSet" }; for (int counter = 0; counter < productInt.Count; counter++) { //// Create an Array of Dynamic Entities DynamicEntity[] dynamicEntities = new DynamicEntity[1]; //// Create a new Dynamic Entity and add it to the Array of Entities dynamicEntities[0] = new DynamicEntity(); dynamicEntities[0].EntityType = entityType; //// Create a Dynamic Entity's Field Value Collection dynamicEntities[0].FieldValueCollection = new DynamicEntityFields(); //// Add the DataCard's Email Address field to the Dynamic Entity’s field collection dynamicEntities[0].FieldValueCollection.Add("Email_Address1", productInt[counter].EmailID); dynamicEntities[0].FieldValueCollection.Add("P11", "<B>" + productInt[counter].Product1ID + "</B>"); dynamicEntities[0].FieldValueCollection.Add("P21", "<B>" + productInt[counter].Product2ID + "</B>"); dynamicEntities[0].FieldValueCollection.Add("P31", "<B>" + productInt[counter].Product3ID + "</B>"); dynamicEntities[0].FieldValueCollection.Add("P1Desc1", productInt[counter].Product1Desc); dynamicEntities[0].FieldValueCollection.Add("P2Desc1", productInt[counter].Product2Desc); dynamicEntities[0].FieldValueCollection.Add("P3Desc1", productInt[counter].Product3Desc); dynamicEntities[0].FieldValueCollection.Add("P1Img1", "<" + productInt[counter].Product1ImgLink + "/>"); dynamicEntities[0].FieldValueCollection.Add("P2Img1", "<" + productInt[counter].Product2ImgLink + "/>"); dynamicEntities[0].FieldValueCollection.Add("P3Img1", "<" + productInt[counter].Product3ImgLink + "/>"); dynamicEntities[0].FieldValueCollection.Add("MappedEntityType", "1"); dynamicEntities[0].FieldValueCollection.Add("MappedEntityID", productInt[counter].ContactId.ToString()); //// Execute the request var result = ServiceProxy.Create(dynamicEntities); //// Verify the status of each DataCard Create request in the results foreach (CreateResult t in result) { //// Successfull requests return a positive integer value for ID if (t.ID != -1) { dataCardId = t.ID; } else { // Extract the Error Message and Error Code for each failed Create request foreach (Error createError in t.Errors) { Response.Write("Exception Message: " + createError.ErrorCode.ToString()); } } } } } catch (System.ServiceModel.FaultException ex) { //// Catch Service Model Fault Exceptions this.MessageBox("Reson: " + ex.Reason.ToString()); this.MessageBox("Fault Type: " + ex.GetType().ToString()); this.MessageBox("Fault Code: " + ex.Code.Name.ToString()); } catch (Exception ex) { //// Catch System Exceptions this.MessageBox("Exception Message: " + ex.Message.ToString()); } }