guides:ws_transaction
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
guides:ws_transaction [2020/08/24 15:03] – brett.zamora | guides:ws_transaction [2020/08/24 18:25] (current) – brett.zamora | ||
---|---|---|---|
Line 178: | Line 178: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | |||
+ | **Comment 1:** | ||
+ | |||
+ | Following is a C# / .NET sample code snippet that shows how to call the transaction web service. This example shows the syntax for calling the web service with or without transaction history, processing the transaction details that are returned and processing the history records that are returned, if history was requested. | ||
+ | |||
+ | This snippet was derived from the [[guides: | ||
+ | |||
+ | |||
+ | <code C#> | ||
+ | private void btnGetStatus_Click(object sender, RoutedEventArgs e) | ||
+ | { | ||
+ | RestClient client = null; | ||
+ | RestRequest request = null; | ||
+ | IRestResponse response = null; | ||
+ | |||
+ | ResetTransactionPanels(); | ||
+ | |||
+ | string strURL = " | ||
+ | |||
+ | // Password has to be hashed. | ||
+ | // New convention uses a Salt value from the user record | ||
+ | // See login web service for more detail. | ||
+ | |||
+ | string strSalt = GetSalt(tbUserName.Text); | ||
+ | string strPassword = tbPassword.Password.ToString(); | ||
+ | |||
+ | string strHashedPassword = HashPassword(strPassword, | ||
+ | |||
+ | string strParms = " | ||
+ | strParms += tbUserName.Text; | ||
+ | strParms += " | ||
+ | strParms += strHashedPassword; | ||
+ | strParms += " | ||
+ | |||
+ | client = new RestClient(strURL); | ||
+ | request = new RestRequest(Method.POST); | ||
+ | |||
+ | request.AddHeader(" | ||
+ | request.AddHeader(" | ||
+ | |||
+ | request.AddParameter(" | ||
+ | response = client.Execute(request); | ||
+ | |||
+ | if (response.IsSuccessful) | ||
+ | { | ||
+ | var jsonResult1 = JsonConvert.DeserializeObject< | ||
+ | string token = jsonResult1.access_token; | ||
+ | |||
+ | if (chkTransactionHistory.IsChecked == true) | ||
+ | { | ||
+ | strURL = " | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | strURL = " | ||
+ | } | ||
+ | |||
+ | client = new RestClient(strURL); | ||
+ | request = new RestRequest(Method.GET); | ||
+ | |||
+ | request.AddHeader(" | ||
+ | request.AddHeader(" | ||
+ | response = client.Execute(request); | ||
+ | |||
+ | if (response.IsSuccessful) | ||
+ | { | ||
+ | if (chkTransactionHistory.IsChecked == true) | ||
+ | { | ||
+ | panelTranDetails.Visibility = Visibility.Visible; | ||
+ | panelTranHistory.Visibility = Visibility.Visible; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | panelTranDetails.Visibility = Visibility.Visible; | ||
+ | panelTranHistory.Visibility = Visibility.Hidden; | ||
+ | } | ||
+ | |||
+ | var jsonResult2 = JsonConvert.DeserializeObject< | ||
+ | |||
+ | tbTransactionID.Text = jsonResult2.result.TRANSACTION_ID; | ||
+ | tbPrimaryRef.Text = jsonResult2.result.PRIMARY_REFERENCE; | ||
+ | tbSecondaryRef.Text = jsonResult2.result.SECONDARY_REFERENCE; | ||
+ | tbCountyName.Text = jsonResult2.result.COUNTY_NAME; | ||
+ | tbSubID.Text = jsonResult2.result.SUBMITTER_ID; | ||
+ | tbAgentID.Text = jsonResult2.result.AGENT_ID; | ||
+ | tbCreatorUserName.Text = jsonResult2.result.CREATOR_USER_NAME; | ||
+ | tbDateCreated.Text = jsonResult2.result.CREATED; | ||
+ | tbLastModified.Text = jsonResult2.result.LAST_MODIFIED; | ||
+ | tbStatusID.Text = jsonResult2.result.TRANSACTION_STATUS_ID; | ||
+ | tbStatusName.Text = jsonResult2.result.TRANSACTION_STATUS; | ||
+ | |||
+ | if (chkTransactionHistory.IsChecked == true) | ||
+ | { | ||
+ | JObject joResponse = JObject.Parse(response.Content); | ||
+ | JArray jaHistory = (JArray)joResponse[" | ||
+ | |||
+ | // Load the grid | ||
+ | |||
+ | historyGrid.Children.Clear(); | ||
+ | historyGrid.RowDefinitions.Clear(); | ||
+ | |||
+ | historyGrid.RowDefinitions.Add(new RowDefinition()); | ||
+ | |||
+ | if (jaHistory.Count == 0) | ||
+ | { | ||
+ | tbMessageLine.Text = "*** No Transaction History Available ***"; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | TextBlock[] txtStatusCode = new TextBlock[jaHistory.Count + 1]; | ||
+ | TextBlock[] txtStatusName = new TextBlock[jaHistory.Count + 1]; | ||
+ | TextBlock[] txtTimeStamp = new TextBlock[jaHistory.Count + 1]; | ||
+ | |||
+ | // Header row | ||
+ | |||
+ | txtStatusCode[0] = new TextBlock(); | ||
+ | txtStatusCode[0].Padding = new Thickness(0, | ||
+ | txtStatusCode[0].Text = " | ||
+ | Grid.SetRow(txtStatusCode[0], | ||
+ | Grid.SetColumn(txtStatusCode[0], | ||
+ | historyGrid.Children.Add(txtStatusCode[0]); | ||
+ | txtStatusName[0] = new TextBlock(); | ||
+ | txtStatusName[0].Padding = new Thickness(0, | ||
+ | txtStatusName[0].Text = " | ||
+ | Grid.SetRow(txtStatusName[0], | ||
+ | Grid.SetColumn(txtStatusName[0], | ||
+ | historyGrid.Children.Add(txtStatusName[0]); | ||
+ | txtTimeStamp[0] = new TextBlock(); | ||
+ | txtTimeStamp[0].Padding = new Thickness(0, | ||
+ | txtTimeStamp[0].Text = " | ||
+ | Grid.SetRow(txtTimeStamp[0], | ||
+ | Grid.SetColumn(txtTimeStamp[0], | ||
+ | historyGrid.Children.Add(txtTimeStamp[0]); | ||
+ | |||
+ | for (int i = 1; i <= jaHistory.Count; | ||
+ | { | ||
+ | historyGrid.RowDefinitions.Add(new RowDefinition()); | ||
+ | |||
+ | txtStatusCode[i] = new TextBlock(); | ||
+ | txtStatusCode[i].Padding = new Thickness(0, | ||
+ | txtStatusCode[i].Text = (String)jaHistory[i - 1][" | ||
+ | Grid.SetRow(txtStatusCode[i], | ||
+ | Grid.SetColumn(txtStatusCode[i], | ||
+ | historyGrid.Children.Add(txtStatusCode[i]); | ||
+ | txtStatusName[i] = new TextBlock(); | ||
+ | txtStatusName[i].Padding = new Thickness(0, | ||
+ | txtStatusName[i].Text = (String)jaHistory[i - 1][" | ||
+ | Grid.SetRow(txtStatusName[i], | ||
+ | Grid.SetColumn(txtStatusName[i], | ||
+ | historyGrid.Children.Add(txtStatusName[i]); | ||
+ | txtTimeStamp[i] = new TextBlock(); | ||
+ | txtTimeStamp[i].Padding = new Thickness(0, | ||
+ | txtTimeStamp[i].Text = (String)jaHistory[i - 1][" | ||
+ | Grid.SetRow(txtTimeStamp[i], | ||
+ | Grid.SetColumn(txtTimeStamp[i], | ||
+ | historyGrid.Children.Add(txtTimeStamp[i]); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | var jsonResult2 = JsonConvert.DeserializeObject< | ||
+ | string strMessage = jsonResult2.Exception.Message; | ||
+ | tbMessageLine.Text = strMessage; | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | var jsonResult2 = JsonConvert.DeserializeObject< | ||
+ | tbMessageLine.Text = jsonResult2.ToString(); | ||
+ | } | ||
+ | return; | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
guides/ws_transaction.1598281426.txt.gz · Last modified: by brett.zamora