protected void btnSyncLead_Click(object sender, EventArgs e) { #region make the syncLead Call string leadEmail = txtEmail.Text; Marketo_WS_2_0.ResultSyncLead resultSyncLead = new Marketo_WS_2_0.ResultSyncLead(); string result = SyncLead(leadEmail, ref resultSyncLead); #endregion }
private string SyncLead(string email, ref Marketo_WS_2_0.ResultSyncLead rs) { Marketo_WS_2_0.SuccessSyncLead response = new Marketo_WS_2_0.SuccessSyncLead(); string results = ""; string userID = txtUserID.Text; string EncryptionKey = txtEncryptionID.Text; string requestTimeStamp = ConvertDateToW3CTime(DateTime.Now); string stringToEncrypt = requestTimeStamp + userID; string message; string key; key = EncryptionKey; message = stringToEncrypt; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetBytes(key); HMACSHA1 hmacsha1 = new HMACSHA1(keyByte); byte[] messageBytes = encoding.GetBytes(message); byte[] hashmessage = hmacsha1.ComputeHash(messageBytes); string header = ByteToString(hashmessage); Marketo_WS_2_0.MktowsContextHeaderInfo ws_context = new Marketo_WS_2_0.MktowsContextHeaderInfo(); ws_context = null; Marketo_WS_2_0.AuthenticationHeaderInfo ws_header = new Marketo_WS_2_0.AuthenticationHeaderInfo(); ws_header.mktowsUserId = userID; ws_header.requestSignature = header.ToLower(); ws_header.requestTimestamp = requestTimeStamp; Marketo_WS_2_0.ParamsSyncLead ws_lead = new Marketo_WS_2_0.ParamsSyncLead(); Marketo_WS_2_0.LeadRecord LeadRec = new Marketo_WS_2_0.LeadRecord(); LeadRec.Email = email; Marketo_WS_2_0.Attribute[] attribList = new Marketo_WS_2_0.Attribute[2]; Marketo_WS_2_0.Attribute att1 = new Marketo_WS_2_0.Attribute(); att1.attrName = "FirstName"; att1.attrValue = "Joe"; attribList[0] = att1; Marketo_WS_2_0.Attribute att2 = new Marketo_WS_2_0.Attribute(); att2.attrName = "LastName"; att2.attrValue = "Smith"; attribList[1] = att2; LeadRec.leadAttributeList = attribList; ws_lead.leadRecord = LeadRec; LeadRec.Email = email; try { response = client.syncLead(ws_header, ws_context, ws_lead); results = ""; rs = response.result; } catch (Exception e) { results = e.Message; rs = null; } return(results); }