public async Task GenerateChallengeAndProcessResponse() { TestLogger.LogMessage(" "); TestLogger.LogMessage("Enter HttpHelper.GenerateChallengeAndProcessResponse()"); TestLogger.LogMessage("Generating challenge.."); PlayReadySoapMessage soapMessage = _serviceRequest.GenerateManualEnablingChallenge(); if (_uri == null) { _uri = soapMessage.Uri; } TestLogger.LogMessage("Getting message body.."); byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; TestLogger.LogMessage("Http Headers:-"); foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); TestLogger.LogMessage(strHeaderName + " : " + strHeaderValue); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); } else { httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } } TestLogger.LogMessage("Http Body:-"); TestLogger.LogMessage(new System.Text.UTF8Encoding().GetString(messageBytes, 0, messageBytes.Length)); HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.PostAsync(_uri, httpContent); string strResponse = await response.Content.ReadAsStringAsync(); TestLogger.LogMessage("Processing Response.."); Exception exResult = _serviceRequest.ProcessManualEnablingResponse(await response.Content.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } TestLogger.LogMessage("Leave HttpHelper.GenerateChallengeAndProcessResponse()"); }
public async Task GenerateChallengeAndProcessResponse() { PlayReadySoapMessage soapMessage = _serviceRequest.GenerateManualEnablingChallenge(); if (_uri == null) { _uri = soapMessage.Uri; } byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); } else { httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } } HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.PostAsync(_uri, httpContent); string strResponse = await response.Content.ReadAsStringAsync(); Exception exResult = _serviceRequest.ProcessManualEnablingResponse(await response.Content.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } }
/// <summary> /// Invoked to acquire the PlayReady License /// </summary> async void LicenseAcquisitionRequest(PlayReadyLicenseAcquisitionServiceRequest licenseRequest, MediaProtectionServiceCompletion completionNotifier, string url, string challengeCustomData) { bool bResult = false; string ExceptionMessage = string.Empty; try { if (!string.IsNullOrEmpty(url)) { Log("ProtectionManager PlayReady Manual License Acquisition Service Request in progress - URL: " + url); if (!string.IsNullOrEmpty(challengeCustomData)) { var encoding = new UTF8Encoding(); byte[] b = encoding.GetBytes(challengeCustomData); licenseRequest.ChallengeCustomData = Convert.ToBase64String(b, 0, b.Length); } PlayReadySoapMessage soapMessage = licenseRequest.GenerateManualEnablingChallenge(); byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); } else { httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } } var licenseAcquision = new CommonLicenseRequest(); HttpContent responseHttpContent = await licenseAcquision.AcquireLicenseAsync(new Uri(url), httpContent); if (responseHttpContent != null) { Exception exResult = licenseRequest.ProcessManualEnablingResponse(await responseHttpContent.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } bResult = true; } else { ExceptionMessage = licenseAcquision.GetLastErrorMessage(); } } else { Log("ProtectionManager PlayReady License Acquisition Service Request in progress - URL: " + licenseRequest.Uri.ToString()); await licenseRequest.BeginServiceRequest(); bResult = true; } } catch (Exception e) { ExceptionMessage = e.Message; } if (bResult == true) { Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request successful" : "ProtectionManager PlayReady License Acquisition Service Request successful"); } else { Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request failed: " + ExceptionMessage : "ProtectionManager PlayReady License Acquisition Service Request failed: " + ExceptionMessage); } completionNotifier.Complete(bResult); }