/// <summary> /// Serializes a given <see cref="Models.V1Dot2.SoapEnvelope"/> instance into a XML string. /// </summary> /// <param name="envelope">The instance to serialize</param> /// <returns>The resulting XML string</returns> public string ToXmlString(Models.V1Dot2.SoapEnvelope envelope) { try { return(ToXmlString <Models.V1Dot2.SoapEnvelope>(envelope)); } catch (Exception e) { throw new SoapEnvelopeV1Dot2SerializationException(envelope, e); } }
private async Task <OnSoapEnvelopeV1Dot2RequestArguments> RunBeforeSoapEnvelopeV1Dot2SerializationHandlers( Models.V1Dot2.SoapEnvelope envelope, string url, string action, Guid trackingId, ISoapHandler[] orderedHandlers, CancellationToken ct) { var beforeSoapEnvelopeSerializationArg = new OnSoapEnvelopeV1Dot2RequestArguments(envelope, url, action, trackingId); foreach (var handler in orderedHandlers) { await handler.OnSoapEnvelopeV1Dot2RequestAsync(this, beforeSoapEnvelopeSerializationArg, ct); handler.OnSoapEnvelopeV1Dot2Request(this, beforeSoapEnvelopeSerializationArg); } return(beforeSoapEnvelopeSerializationArg); }
private async Task <OnSoapEnvelopeV1Dot2ResponseArguments> RunAfterSoapEnvelopeV1Dot2DeserializationHandler(Models.V1Dot2.SoapEnvelope envelope, string url, string action, Guid trackingId, object state, ISoapHandler[] orderedHandlers, CancellationToken ct) { var afterSoapEnvelopeDeserializationArguments = new OnSoapEnvelopeV1Dot2ResponseArguments(envelope, url, action, trackingId) { State = state }; for (var index = orderedHandlers.Length - 1; index >= 0; index--) { var handler = orderedHandlers[index]; await handler.OnSoapEnvelopeV1Dot2ResponseAsync(this, afterSoapEnvelopeDeserializationArguments, ct); handler.OnSoapEnvelopeV1Dot2Response(this, afterSoapEnvelopeDeserializationArguments); } return(afterSoapEnvelopeDeserializationArguments); }
/// <summary> /// Sends the given <see cref="Models.V1Dot2.SoapEnvelope"/> into the specified url. /// </summary> /// <param name="url">The url that will receive the request</param> /// <param name="action">The SOAP Action beeing performed</param> /// <param name="requestEnvelope">The <see cref="SoapEnvelope"/> to be sent</param> /// <returns>The resulting <see cref="SoapEnvelope"/></returns> /// <exception cref="ArgumentNullException"></exception> public virtual Models.V1Dot2.SoapEnvelope Send(string url, string action, Models.V1Dot2.SoapEnvelope requestEnvelope) { return(SendAsync(url, action, requestEnvelope).ConfigureAwait(false).GetAwaiter().GetResult()); }
/// <summary> /// Sends the given <see cref="Models.V1Dot2.SoapEnvelope"/> into the specified url. /// </summary> /// <param name="url">The url that will receive the request</param> /// <param name="action">The SOAP action beeing performed</param> /// <param name="requestEnvelope">The <see cref="SoapEnvelope"/> to be sent</param> /// <param name="ct">The cancellation token</param> /// <returns>A task to be awaited for the result</returns> /// <exception cref="ArgumentNullException"></exception> public virtual async Task <Models.V1Dot2.SoapEnvelope> SendAsync( string url, string action, Models.V1Dot2.SoapEnvelope requestEnvelope, CancellationToken ct = default(CancellationToken)) { var trackingId = Guid.NewGuid(); var orderedHandlers = _handlers.OrderBy(e => e.Order).ToArray(); var beforeSoapEnvelopeSerializationHandlersResult = await RunBeforeSoapEnvelopeV1Dot2SerializationHandlers( requestEnvelope, url, action, trackingId, orderedHandlers, ct); string requestXml; try { requestXml = Settings.SerializationProvider.ToXmlString(beforeSoapEnvelopeSerializationHandlersResult.Envelope); } catch (SoapEnvelopeV1Dot2SerializationException) { throw; } catch (Exception e) { throw new SoapEnvelopeV1Dot2SerializationException(requestEnvelope, e); } var beforeHttpRequestHandlersResult = await RunBeforeHttpRequestHandlers( requestXml, url, action, trackingId, beforeSoapEnvelopeSerializationHandlersResult.State, orderedHandlers, Constant.SoapEnvelopeVersion.V1Dot2, ct); var response = await HttpClient.SendAsync(beforeHttpRequestHandlersResult.Request, ct).ConfigureAwait(false); var afterHttpResponseHandlersResult = await RunAfterHttpResponseHandlers( response, url, action, trackingId, beforeHttpRequestHandlersResult.State, orderedHandlers, ct); var responseXml = await afterHttpResponseHandlersResult.Response.Content.ReadAsStringAsync().ConfigureAwait(false); if (string.IsNullOrWhiteSpace(responseXml)) { throw new SoapEnvelopeV1Dot2DeserializationException(responseXml, "The response content is empty."); } Models.V1Dot2.SoapEnvelope responseEnvelope; try { responseEnvelope = Settings.SerializationProvider.ToSoapEnvelopeV1Dot2(responseXml); } catch (SoapEnvelopeV1Dot2DeserializationException) { throw; } catch (Exception e) { throw new SoapEnvelopeV1Dot2DeserializationException(responseXml, e); } var afterSoapEnvelopeDeserializationHandlerResult = await RunAfterSoapEnvelopeV1Dot2DeserializationHandler( responseEnvelope, url, action, trackingId, afterHttpResponseHandlersResult.State, orderedHandlers, ct); return(afterSoapEnvelopeDeserializationHandlerResult.Envelope); }