public static async Task <WsTrustResponse> SendRequestAsync(WsTrustAddress wsTrustAddress, UserCredential credential, CallState callState, string cloudAudience) { IHttpClient request = PlatformPlugin.HttpClientFactory.Create(wsTrustAddress.Uri.AbsoluteUri, callState); request.ContentType = "application/soap+xml"; if (credential.UserAuthType == UserAuthType.IntegratedAuth) { SetKerberosOption(request); } if (string.IsNullOrEmpty(cloudAudience)) { cloudAudience = defaultAppliesTo; } StringBuilder messageBuilder = BuildMessage(cloudAudience, wsTrustAddress, credential); string soapAction = XmlNamespace.Issue.ToString(); if (wsTrustAddress.Version == WsTrustVersion.WsTrust2005) { soapAction = XmlNamespace.Issue2005.ToString(); } WsTrustResponse wstResponse; try { request.BodyParameters = new StringRequestParameters(messageBuilder); request.Headers["SOAPAction"] = soapAction; IHttpWebResponse response = await request.GetResponseAsync().ConfigureAwait(false); wstResponse = WsTrustResponse.CreateFromResponse(EncodingHelper.GenerateStreamFromString(response.ResponseString), wsTrustAddress.Version); } catch (HttpRequestWrapperException ex) { string errorMessage; try { using (Stream stream = EncodingHelper.GenerateStreamFromString(ex.WebResponse.ResponseString)) { XDocument responseDocument = WsTrustResponse.ReadDocumentFromResponse(stream); errorMessage = WsTrustResponse.ReadErrorResponse(responseDocument, callState); } } catch (AdalException) { errorMessage = "See inner exception for detail."; } throw new AdalServiceException( AdalError.FederatedServiceReturnedError, string.Format(AdalErrorMessage.FederatedServiceReturnedErrorTemplate, wsTrustAddress.Uri, errorMessage), null, ex); } return(wstResponse); }
public static async Task <WsTrustResponse> SendRequestAsync(WsTrustAddress wsTrustAddress, UserCredential credential, CallState callState) { IHttpWebRequest request = NetworkPlugin.HttpWebRequestFactory.Create(wsTrustAddress.Uri.AbsoluteUri); request.ContentType = "application/soap+xml;"; if (credential.UserAuthType == UserAuthType.IntegratedAuth) { SetKerberosOption(request); } StringBuilder messageBuilder = BuildMessage(DefaultAppliesTo, wsTrustAddress, credential); string soapAction = XmlNamespace.Issue.ToString(); if (wsTrustAddress.Version == WsTrustVersion.WsTrust2005) { soapAction = XmlNamespace.Issue2005.ToString(); } Dictionary <string, string> headers = new Dictionary <string, string> { { "SOAPAction", soapAction } }; WsTrustResponse wstResponse; try { HttpHelper.SetPostRequest(request, new RequestParameters(messageBuilder), callState, headers); IHttpWebResponse response = await request.GetResponseSyncOrAsync(callState); wstResponse = WsTrustResponse.CreateFromResponse(response.GetResponseStream(), wsTrustAddress.Version); } catch (WebException ex) { string errorMessage; try { XDocument responseDocument = WsTrustResponse.ReadDocumentFromResponse(ex.Response.GetResponseStream()); errorMessage = WsTrustResponse.ReadErrorResponse(responseDocument, callState); } catch (AdalException) { errorMessage = "See inner exception for detail."; } throw new AdalServiceException( AdalError.FederatedServiceReturnedError, string.Format(AdalErrorMessage.FederatedServiceReturnedErrorTemplate, wsTrustAddress.Uri, errorMessage), null, ex); } return(wstResponse); }