/// <inheritdoc/> public async Task <WsTrustResponse> GetWsTrustResponseAsync( WsTrustEndpoint wsTrustEndpoint, string wsTrustRequest, RequestContext requestContext) { var headers = new Dictionary <string, string> { { "SOAPAction", (wsTrustEndpoint.Version == WsTrustVersion.WsTrust2005) ? XmlNamespace.Issue2005.ToString() : XmlNamespace.Issue.ToString() } }; var body = new StringContent( wsTrustRequest, Encoding.UTF8, "application/soap+xml"); HttpResponse resp = await _httpManager.SendPostForceResponseAsync(wsTrustEndpoint.Uri, headers, body, requestContext.Logger, cancellationToken : requestContext.UserCancellationToken).ConfigureAwait(false); if (resp.StatusCode != System.Net.HttpStatusCode.OK) { string errorMessage = null; try { errorMessage = WsTrustResponse.ReadErrorResponse(XDocument.Parse(resp.Body, LoadOptions.None), requestContext); } catch (System.Xml.XmlException) { errorMessage = resp.Body; } string message = string.Format( CultureInfo.CurrentCulture, MsalErrorMessage.FederatedServiceReturnedErrorTemplate, wsTrustEndpoint.Uri, errorMessage); throw MsalServiceExceptionFactory.FromHttpResponse( MsalError.FederatedServiceReturnedError, message, resp); } try { return(WsTrustResponse.CreateFromResponse(resp.Body, wsTrustEndpoint.Version)); } catch (System.Xml.XmlException ex) { string message = string.Format( CultureInfo.CurrentCulture, MsalErrorMessage.ParsingWsTrustResponseFailedErrorTemplate, wsTrustEndpoint.Uri, resp.Body); throw new MsalClientException( MsalError.ParsingWsTrustResponseFailed, message, ex); } }
/// <inheritdoc/> public async Task <WsTrustResponse> GetWsTrustResponseAsync( WsTrustEndpoint wsTrustEndpoint, string wsTrustRequest, RequestContext requestContext) { var headers = new Dictionary <string, string> { { "ContentType", "application/soap+xml" }, { "SOAPAction", (wsTrustEndpoint.Version == WsTrustVersion.WsTrust2005) ? XmlNamespace.Issue2005.ToString() : XmlNamespace.Issue.ToString() } }; var body = new StringContent( wsTrustRequest, Encoding.UTF8, headers["ContentType"]); IHttpWebResponse resp = await _httpManager.SendPostForceResponseAsync(wsTrustEndpoint.Uri, headers, body, requestContext).ConfigureAwait(false); if (resp.StatusCode != System.Net.HttpStatusCode.OK) { string errorMessage = null; try { errorMessage = WsTrustResponse.ReadErrorResponse(XDocument.Parse(resp.Body, LoadOptions.None), requestContext); } catch (System.Xml.XmlException) { errorMessage = resp.Body; } throw MsalExceptionFactory.GetServiceException( CoreErrorCodes.FederatedServiceReturnedError, string.Format( CultureInfo.CurrentCulture, CoreErrorMessages.FederatedServiceReturnedErrorTemplate, wsTrustEndpoint.Uri, errorMessage), new ExceptionDetail() { StatusCode = (int)resp.StatusCode, ResponseBody = resp.Body, HttpResponseHeaders = resp.Headers }); } try { return(WsTrustResponse.CreateFromResponse(resp.Body, wsTrustEndpoint.Version)); } catch (System.Xml.XmlException ex) { throw MsalExceptionFactory.GetClientException( CoreErrorCodes.ParsingWsTrustResponseFailed, CoreErrorCodes.ParsingWsTrustResponseFailed, ex); } }