public override void Execute(Context context) { _request = RequestBody.Load(context); context.LogXmlData("Request", _request, true); _response = CallWebMethod( _request, ServiceUrl, Action, Username, Password, context); Stream responseForPostProcessing = _response; foreach(var subStep in SubSteps) { responseForPostProcessing = subStep.Execute(responseForPostProcessing, context); } }
private Stream CallWebMethod( Stream requestData, string serviceUrl, string action, string username, string password, Context ctx ) { try { Stream responseData; BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; binding.UseDefaultWebProxy = true; EndpointAddress epa = new EndpointAddress(new Uri(serviceUrl)); ChannelFactory<genericContract> cf = null; genericContract channel; Message request; Message response; string responseString; try { cf = new ChannelFactory<genericContract>(binding, epa); cf.Credentials.UserName.UserName = username; cf.Credentials.UserName.Password = password; cf.Open(); channel = cf.CreateChannel(); using (new OperationContextScope((IContextChannel)channel)) { XmlReader r = new XmlTextReader(requestData); request = Message.CreateMessage(MessageVersion.Soap11, action, r); foreach (var header in _soapHeaders) { MessageHeader messageHeader = MessageHeader.CreateHeader(header.HeaderName, header.HeaderNameSpace, header.HeaderInstance); OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader); } response = channel.Invoke(request); string responseStr = response.GetReaderAtBodyContents().ReadOuterXml(); ctx.LogXmlData("Response", responseStr); responseData = StreamHelper.LoadMemoryStream(responseStr); } request.Close(); response.Close(); cf.Close(); } catch (CommunicationException ce) { ctx.LogException(ce); if (cf != null) { cf.Abort(); } throw; } catch (TimeoutException te) { ctx.LogException(te); if (cf != null) { cf.Abort(); } throw; } catch (Exception e) { ctx.LogException(e); if (cf != null) { cf.Abort(); } throw; } return responseData; } catch (Exception ex) { ctx.LogException(ex); throw; } }