Changeset 4749

Show
Ignore:
Timestamp:
07/23/08 18:05:36 (4 months ago)
Author:
xmlhacker
Message:

synching with private repository

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Agent.cs

    r4729 r4749  
    1515using log4net; 
    1616using log4net.Config; 
     17using System.Web; 
     18using Nuxleus.Extension; 
     19using System.Web.Configuration; 
    1720 
    1821namespace Nuxleus.Extension.Aws { 
    1922 
    20     public struct Agent<T> { 
    21  
    22         static readonly ILog m_loggerInstance = LogManager.GetLogger(typeof(T)); 
     23    public struct Agent { 
    2324 
    2425        static LoggerScope logger = new LoggerScope(); 
     
    2728        static int m_workers = (int.Parse(ConfigurationManager.AppSettings["WorkerQueueMultiplier"]) * System.Environment.ProcessorCount); 
    2829 
    29         public static ILog GetBasicLogger() { 
    30             XmlConfigurator.Configure(new System.IO.FileInfo(("log4net.config"))); 
    31             return m_loggerInstance; 
    32         } 
    33  
    3430        public void Initialize() { 
    3531            ServicePointManager.DefaultConnectionLimit = int.Parse(ConfigurationManager.AppSettings["DefaultConnectionLimit"]); 
     32             
     33            //EnableDnsRoundRobin is not implemented on Mono 
     34            ServicePointManager.EnableDnsRoundRobin = true; 
     35 
     36            //ServicePointManager.Expect100Continue = true; 
     37            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
     38            HttpRuntimeSection configSection = (HttpRuntimeSection)config.GetSection("system.web/httpRuntime"); 
     39            this.LogInfo("ServicePointManager Default Connection Limit: {0}", ServicePointManager.DefaultConnectionLimit); 
     40            this.LogInfo("system.web/httpRuntime/minFreeThreads: {0}", configSection.MinFreeThreads); 
     41            this.LogInfo("system.web/httpRuntime/minLocalRequestFreeThreads: {0}", configSection.MinLocalRequestFreeThreads); 
     42 
    3643            int minWorkerThreads = int.Parse(ConfigurationManager.AppSettings["MinimumWorkerThreads"]); 
    3744            int minAsyncIOThreads = int.Parse(ConfigurationManager.AppSettings["MinimumAsyncIOThreds"]); 
     
    5158 
    5259            scope.Begin = () => { 
    53                 using (WorkerQueue q = new WorkerQueue(m_workers)) { 
     60                using (IEnumerableTWorkerQueue<IAsync> q = new IEnumerableTWorkerQueue<IAsync>(m_workers)) { 
    5461                    List<string> lines = new List<string>(); 
    5562                    using (StreamReader csvReader = new StreamReader(fileName, Encoding.UTF8, true)) { 
     
    8895 
    8996        private static IEnumerable<IAsync> InvokeOperation<T>(List<string> operation) { 
    90             Dictionary<IRequest, T> responseList = new Dictionary<IRequest, T>(); 
    9197            IEnumerable<IAsync>[] processList = new IEnumerable<IAsync>[operation.Count]; 
    9298            int i = 0; 
    9399            foreach (string inputLine in operation) { 
    94100                string[] inputArray = inputLine.Split(new char[] { '\u0009' }); 
    95                 processList[i] = CreateTask<T>(inputArray).Invoke(responseList); 
     101                processList[i] = CreateTask(inputArray).InvokeAsync(); 
    96102                i++; 
    97103            } 
     
    99105        } 
    100106 
    101         private static PutAttributes CreateTask<T>(string[] inputArray) { 
     107        private static PutAttributes CreateTask(string[] inputArray) { 
    102108 
    103109            KeyValuePair<string, string>[] geoNames = 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Handler/ExceptionHandler.cs

    r4729 r4749  
    1111namespace Nuxleus.Extension.Aws.SimpleDb { 
    1212    public class ExceptionHandlerScope : HandlerBase { 
    13  
    14         WebException we; 
    1513 
    1614        protected override void Call() { 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Nuxleus.Extension.Aws.csproj

    r4730 r4749  
    99    <OutputType>Library</OutputType> 
    1010    <AppDesignerFolder>Properties</AppDesignerFolder> 
    11     <RootNamespace>Nuxleus.Extension.AWS</RootNamespace> 
    12     <AssemblyName>Nuxleus.Extension.AWS</AssemblyName> 
     11    <RootNamespace>Nuxleus.Extension.Aws</RootNamespace> 
     12    <AssemblyName>Nuxleus.Extension.Aws</AssemblyName> 
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 
    1414    <FileAlignment>512</FileAlignment> 
     
    4949      <RequiredTargetFramework>3.0</RequiredTargetFramework> 
    5050    </Reference> 
     51    <Reference Include="System.Management" /> 
    5152    <Reference Include="System.Runtime.Serialization"> 
    5253      <RequiredTargetFramework>3.0</RequiredTargetFramework> 
     
    5657    </Reference> 
    5758    <Reference Include="System.Web" /> 
     59    <Reference Include="System.Web.Extensions"> 
     60      <RequiredTargetFramework>3.5</RequiredTargetFramework> 
     61    </Reference> 
    5862    <Reference Include="System.Web.Services" /> 
    5963    <Reference Include="System.Xml" /> 
     
    6468  <ItemGroup> 
    6569    <Compile Include="Agent.cs" /> 
     70    <Compile Include="AwsBaseConnection\HttpQueryConnection.cs" /> 
     71    <Compile Include="AwsBaseConnection\IAwsConnection.cs" /> 
     72    <Compile Include="Extensions\ExtensionMethods.cs" /> 
     73    <Compile Include="LoadBalancer\SimpleDBProcessQueue.cs" /> 
     74    <Compile Include="NoLoadBalanceAgent.cs" /> 
     75    <Compile Include="LoadBalancer\TaskWorkerQueue.cs" /> 
     76    <Compile Include="Process\SimpleDBProcess.cs"> 
     77      <SubType>Component</SubType> 
     78    </Compile> 
     79    <Compile Include="SyncAgent.cs" /> 
    6680    <Compile Include="Handler\ExceptionHandler.cs" /> 
    67     <Compile Include="HttpQueryConnection.cs" /> 
    68     <Compile Include="IAwsConnection.cs" /> 
     81    <Compile Include="LoadBalancer\IEnumerableIAsyncWorkerQueue.cs" /> 
    6982    <Compile Include="LoadBalancer\WorkerQueue.cs" /> 
    7083    <Compile Include="Properties\AssemblyInfo.cs" /> 
     
    104117  </ItemGroup> 
    105118  <ItemGroup> 
     119    <None Include="app.config"> 
     120      <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
     121    </None> 
    106122    <None Include="Extf.Net.snk" /> 
    107123    <None Include="log4net.config"> 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Properties/AssemblyInfo.cs

    r4148 r4749  
    22using System.Runtime.CompilerServices; 
    33using System.Runtime.InteropServices; 
     4using System.Security; 
    45 
    56// General Information about an assembly is controlled through the following  
    67// set of attributes. Change these attribute values to modify the information 
    78// associated with an assembly. 
    8 [assembly: AssemblyTitle("Nuxleus.Extension.AWS")] 
     9[assembly: AssemblyTitle("Nuxleus.Extension.Aws")] 
    910[assembly: AssemblyDescription("")] 
    1011[assembly: AssemblyConfiguration("")] 
    1112[assembly: AssemblyCompany("third&urban")] 
    12 [assembly: AssemblyProduct("Nuxleus.Extension.AWS")] 
     13[assembly: AssemblyProduct("Nuxleus.Extension.Aws")] 
    1314[assembly: AssemblyCopyright("Copyright © third&urban 2007")] 
    1415[assembly: AssemblyTrademark("")] 
     
    3536[assembly: AssemblyVersion("1.0.0.0")] 
    3637[assembly: AssemblyFileVersion("1.0.0.0")] 
     38[assembly: AllowPartiallyTrustedCallers] 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Properties/Settings.Designer.cs

    r4715 r4749  
    99//------------------------------------------------------------------------------ 
    1010 
    11 namespace Nuxleus.Extension.AWS.Properties { 
     11namespace Nuxleus.Extension.Aws.Properties { 
    1212     
    1313     
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Request/IRequest.cs

    r4729 r4749  
    88    public interface IRequest { 
    99        KeyValuePair<string, string>[] Headers { get; } 
    10         RequestType RequestType { get; } 
     10        SdbRequestType RequestType { get; } 
    1111        String RequestMessage { get; set; } 
    1212    } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Response/IResponse.cs

    r4729 r4749  
    88    public interface IResponse { 
    99        KeyValuePair<string,string>[] Headers { get; set;} 
    10         String Response { get;
     10        String Response { get; set;
    1111    } 
    1212} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/Scope/LoggerScope.cs

    r4729 r4749  
    44using System.Text; 
    55using VVMF.SOA.Common; 
     6using System.Security.Permissions; 
    67 
    78namespace Nuxleus.Extension.Aws.SimpleDb 
    89{ 
     10 
     11    //[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] 
    912    public class LoggerScope : HandlerBase 
    1013    { 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Operation/Operation.cs

    r4729 r4749  
    77 
    88namespace Nuxleus.Extension.Aws.SimpleDb { 
    9     public struct Operation<T> { 
    10  
     9    public static class Operation { 
     10        //public static Async<String> GetResultAsync<T>(this Agent<T> req) { 
     11        //    return new AsyncPrimitive<String>(req.BeginInvoke, req.EndInvoke); 
     12        //} 
    1113    } 
    1214} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/CreateDomainRequest.cs

    r4729 r4749  
    2121        } 
    2222 
    23         public RequestType RequestType { 
     23        public SdbRequestType RequestType { 
    2424            get { 
    25                 return RequestType.CreateDomain; 
     25                return SdbRequestType.CreateDomain; 
    2626            } 
    2727        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/DeleteDomainRequest.cs

    r4729 r4749  
    2121        } 
    2222 
    23         public RequestType RequestType { 
     23        public SdbRequestType RequestType { 
    2424            get { 
    25                 return RequestType.DeleteDomain; 
     25                return SdbRequestType.DeleteDomain; 
    2626            } 
    2727        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/GetAttributesRequest.cs

    r4729 r4749  
    2121        } 
    2222 
    23         public RequestType RequestType { 
     23        public SdbRequestType RequestType { 
    2424            get { 
    25                 return RequestType.GetAttributes; 
     25                return SdbRequestType.GetAttributes; 
    2626            } 
    2727        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/ListDomainsRequest.cs

    r4729 r4749  
    2121        } 
    2222 
    23         public RequestType RequestType { 
     23        public SdbRequestType RequestType { 
    2424            get { 
    25                 return RequestType.ListDomains; 
     25                return SdbRequestType.ListDomains; 
    2626            } 
    2727        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/PutAttributesRequest.cs

    r4729 r4749  
    2121        } 
    2222 
    23         public RequestType RequestType { 
     23        public SdbRequestType RequestType { 
    2424            get { 
    25                 return RequestType.PutAttributes; 
     25                return SdbRequestType.PutAttributes; 
    2626            } 
    2727        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Request/QueryRequest.cs

    r4729 r4749  
    2121        } 
    2222 
    23         public RequestType RequestType { 
     23        public SdbRequestType RequestType { 
    2424            get { 
    25                 return RequestType.Query; 
     25                return SdbRequestType.Query; 
    2626            } 
    2727        } 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/CreateDomainResponse.cs

    r4729 r4749  
    77 
    88    public struct CreateDomainResponse : IResponse { 
    9         #region IResponse Members 
    10  
    11         public KeyValuePair<string, string>[] Headers { 
    12             get { 
    13                 throw new NotImplementedException(); 
    14             } 
    15             set { 
    16                 throw new NotImplementedException(); 
    17             } 
    18         } 
    19  
    20         public string Response { 
    21             get { 
    22                 throw new NotImplementedException(); 
    23             } 
    24         } 
    25  
    26         #endregion 
     9        public KeyValuePair<string, string>[] Headers { get; set; } 
     10        public string Response { get; set; } 
    2711    } 
    2812} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/DeleteDomainResponse.cs

    r4729 r4749  
    77 
    88    public struct DeleteDomainResponse : IResponse { 
    9         #region IResponse Members 
    10  
    11         public KeyValuePair<string, string>[] Headers { 
    12             get { 
    13                 throw new NotImplementedException(); 
    14             } 
    15             set { 
    16                 throw new NotImplementedException(); 
    17             } 
    18         } 
    19  
    20         public string Response { 
    21             get { 
    22                 throw new NotImplementedException(); 
    23             } 
    24         } 
    25  
    26         #endregion 
     9        public KeyValuePair<string, string>[] Headers { get; set; } 
     10        public string Response { get; set; } 
    2711    } 
    2812} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/GetAttributesResponse.cs

    r4729 r4749  
    77 
    88    public struct GetAttributesResponse : IResponse { 
    9         #region IResponse Members 
    10  
    11         public KeyValuePair<string, string>[] Headers { 
    12             get { 
    13                 throw new NotImplementedException(); 
    14             } 
    15             set { 
    16                 throw new NotImplementedException(); 
    17             } 
    18         } 
    19  
    20         public string Response { 
    21             get { 
    22                 throw new NotImplementedException(); 
    23             } 
    24         } 
    25  
    26         #endregion 
     9        public KeyValuePair<string, string>[] Headers { get; set; } 
     10        public string Response { get; set; } 
    2711    } 
    2812} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/ListDomainsResponse.cs

    r4729 r4749  
    77 
    88    public struct ListDomainsResponse : IResponse { 
    9         #region IResponse Members 
    10  
    11         public KeyValuePair<string, string>[] Headers { 
    12             get { 
    13                 throw new NotImplementedException(); 
    14             } 
    15             set { 
    16                 throw new NotImplementedException(); 
    17             } 
    18         } 
    19  
    20         public string Response { 
    21             get { 
    22                 throw new NotImplementedException(); 
    23             } 
    24         } 
    25  
    26         #endregion 
     9        public KeyValuePair<string, string>[] Headers { get; set; } 
     10        public string Response { get; set; } 
    2711    } 
    2812} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/PutAttributesResponse.cs

    r4729 r4749  
    11using System; 
    22using System.Collections.Generic; 
    3 using System.Linq; 
    4 using System.Text; 
    53 
    64namespace Nuxleus.Extension.Aws.SimpleDb { 
    75 
    86    public struct PutAttributesResponse : IResponse { 
    9         #region IResponse Members 
    10  
    11         public KeyValuePair<string, string>[] Headers { 
    12             get { 
    13                 throw new NotImplementedException(); 
    14             } 
    15             set { 
    16                 throw new NotImplementedException(); 
    17             } 
    18         } 
    19  
    20         public string Response { 
    21             get { 
    22                 throw new NotImplementedException(); 
    23             } 
    24         } 
    25  
    26         #endregion 
     7        public KeyValuePair<string, string>[] Headers { get; set; } 
     8        public string Response { get; set; } 
    279    } 
    2810} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/Response/QueryResponse.cs

    r4729 r4749  
    77 
    88    public struct QueryResponse : IResponse { 
    9         #region IResponse Members 
    10  
    11         public KeyValuePair<string, string>[] Headers { 
    12             get { 
    13                 throw new NotImplementedException(); 
    14             } 
    15             set { 
    16                 throw new NotImplementedException(); 
    17             } 
    18         } 
    19  
    20         public string Response { 
    21             get { 
    22                 throw new NotImplementedException(); 
    23             } 
    24         } 
    25  
    26         #endregion 
     9        public KeyValuePair<string, string>[] Headers { get; set; } 
     10        public string Response { get; set; } 
    2711    } 
    2812} 
  • trunk/nuxleus/Source/Nuxleus.Extension.Aws/SimpleDB/SimpleDBService.cs

    r4729 r4749  
    2020namespace Nuxleus.Extension.Aws.SimpleDb { 
    2121 
    22     public enum RequestType { 
     22    public enum SdbRequestType { 
    2323        [Label("Query")] 
    2424        Query, 
     
    3737    } 
    3838 
    39     public struct SimpleDBService<TRequestType> { 
    40  
    41         static string AWS_PUBLIC_KEY = System.Environment.GetEnvironmentVariable("AWS_PUBLIC_KEY"); 
    42         static string AWS_PRIVATE_KEY = System.Environment.GetEnvironmentVariable("AWS_PRIVATE_KEY"); 
    43         static XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 
    44         static XNamespace aws = "http://sdb.amazonaws.com/doc/2007-11-07/"; 
    45         static XNamespace i = "http://www.w3.org/2001/XMLSchema-instance"; 
     39    public enum WebServiceType { 
     40        SOAP, 
     41        REST, 
     42        QUERY 
     43    } 
     44 
     45    public struct HttpRequestSettings { 
     46        public WebServiceType WebServiceType { get; set; } 
     47        public int Timeout { get; set; } 
     48        public bool KeepAlive { get; set; } 
     49        public bool Pipelined { get; set; } 
     50        public string Method { get; set; } 
     51        public string ContentType { get; set; } 
     52    } 
     53 
     54    public struct HttpWebService<TRequestType> { 
     55 
     56        static readonly string AWS_PUBLIC_KEY = System.Environment.GetEnvironmentVariable("AWS_PUBLIC_KEY"); 
     57        static readonly string AWS_PRIVATE_KEY = System.Environment.GetEnvironmentVariable("AWS_PRIVATE_KEY"); 
     58        static readonly string AWS_URI_ENDPOINT = System.Environment.GetEnvironmentVariable("AWS_URI_ENDPOINT"); 
     59        static readonly XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/"; 
     60        static readonly XNamespace aws = "http://sdb.amazonaws.com/doc/2007-11-07/"; 
     61        static readonly XNamespace i = "http://www.w3.org/2001/XMLSchema-instance"; 
    4662        static XmlSerializer m_xSerializer = new XmlSerializer(typeof(TRequestType)); 
    47         static ILog m_logger = Agent<SimpleDBService<TRequestType>>.GetBasicLogger(); 
    48  
    49         public static IEnumerable<IAsync> CallWebService<TResultType>(ITask task, IRequest sdbRequest, Dictionary<IRequest, TResultType> responseList) { 
    50  
    51             Encoding encoding = new UTF8Encoding(); 
    52  
    53             HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sdb.amazonaws.com/"); 
    54             request.Timeout = 30000 /*TODO: This should be set dynamically*/; 
     63        static Encoding m_encoding = new UTF8Encoding(); 
     64 
     65        public static IResponse CallWebServiceSync(ITask task) { 
     66 
     67            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AWS_URI_ENDPOINT); 
     68            request.Timeout = 5000 /*TODO: This should be set dynamically*/; 
    5569            request.KeepAlive = true; 
    56             request.Pipelined = false; 
     70            request.Pipelined = true; 
     71 
     72            IRequest sdbRequest = task.Request; 
    5773 
    5874            StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
     
    6985            string soapMessage = output.ToString(); 
    7086            sdbRequest.RequestMessage = soapMessage; 
    71             m_logger.DebugFormat("SOAP message for task {0}: {1}", task.TaskID, soapMessage); 
    72  
    73             byte[] buffer = encoding.GetBytes(soapMessage); 
     87            Log.LogDebug<HttpWebService<TRequestType>>("SOAP message for task {0}: {1}", task.TaskID, soapMessage); 
     88 
     89            byte[] buffer = m_encoding.GetBytes(soapMessage); 
    7490 
    7591            int contentLength = buffer.Length; 
     
    8298            } 
    8399 
    84             m_logger.DebugFormat("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 
     100            Log.LogDebug<HttpWebService<TRequestType>>("Start Request: Thread is background: {0}, Thread ID: {1}, Thread is managed: {2}", Thread.CurrentThread.IsBackground, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread); 
    85101 
    86102            using (Stream newStream = request.GetRequestStream()) { 
    87103                newStream.Write(buffer, 0, contentLength); 
    88                 m_logger.DebugFormat("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
    89                 Async<WebResponse> response = request.GetResponseAsync(); 
    90                 yield return response; 
    91                 m_logger.DebugFormat("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
    92                 Stream stream = response.Result.GetResponseStream(); 
    93                 Async<TResultType> responseObject = stream.ReadToEndAsync<TResultType>().ExecuteAsync<TResultType>(); 
    94                 yield return responseObject; 
    95                 responseList.Add(sdbRequest, responseObject.Result); 
     104                Log.LogInfo<HttpWebService<TRequestType>>("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
     105                WebResponse response = request.GetResponse(); 
     106                Log.LogInfo<HttpWebService<TRequestType>>("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
     107                using (StreamReader stream = new StreamReader(response.GetResponseStream())) { 
     108                    task.Response.Response = stream.ReadToEnd(); 
     109                } 
     110                return task.Response; 
     111            } 
     112        } 
     113 
     114        public static IEnumerable<IAsync> CallWebService(ITask task) { 
     115 
     116            IRequest sdbRequest = task.Request; 
     117 
     118            StringBuilder output = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
     119            using (XmlReader xreader = CreateSoapMessage(task, LabelAttribute.FromMember(sdbRequest.RequestType)).CreateReader()) { 
     120                while (xreader.Read()) { 
     121                    if (xreader.IsStartElement()) { 
     122                        output.Append(xreader.ReadOuterXml()); 
     123                    } 
     124                } 
     125            } 
     126 
     127            string soapMessage = output.ToString(); 
     128            sdbRequest.RequestMessage = soapMessage; 
     129            byte[] buffer = m_encoding.GetBytes(soapMessage); 
     130 
     131            int contentLength = buffer.Length; 
     132 
     133            HttpWebRequest request = null; 
     134 
     135            try { 
     136                request = (HttpWebRequest)WebRequest.Create(AWS_URI_ENDPOINT); 
     137                request.Timeout = 10000 /*TODO: This should be set dynamically*/; 
     138                request.KeepAlive = true; 
     139                request.Pipelined = true; 
     140                request.ContentLength = contentLength; 
     141                request.Method = "POST"; 
     142                request.ContentType = "application/soap+xml"; 
     143            } catch (UriFormatException ufe) { 
     144                Log.LogInfo<HttpWebService<TRequestType>>("Caught UriFormatException on WebRequest.Create: {0}", ufe.Message); 
     145            } 
     146 
     147            foreach (KeyValuePair<string, string> header in sdbRequest.Headers) { 
     148                request.Headers.Add(header.Key, header.Value); 
     149            } 
     150 
     151            Stream webStream = null; 
     152 
     153            try { 
     154                webStream = request.GetRequestStream(); 
     155            } catch (WebException we) { 
     156                Log.LogInfo<HttpWebService<TRequestType>>("Caught WebException on GetResponseAsync: {0}", we.Message); 
     157            } 
     158            if (webStream != null) { 
     159                using (webStream) { 
     160                    webStream.Write(buffer, 0, contentLength); 
     161                    Log.LogInfo<HttpWebService<TRequestType>>("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
     162 
     163                    Async<WebResponse> response = null; 
     164                    try { 
     165                        response = request.GetResponseAsync(); 
     166                        Log.LogInfo<HttpWebService<TRequestType>>("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
     167                    } catch (WebException we) { 
     168                        Log.LogDebug<HttpWebService<TRequestType>>("The call to GetResponseAsync for {0} failed with the error: {1}.", task.TaskID, we.Message); 
     169                        //TODO: Add the failed task to a retry queue. 
     170                    } 
     171                    if (response != null) { 
     172                        yield return response; 
     173                        Stream stream = null; 
     174                        try { 
     175                            stream = response.Result.GetResponseStream(); 
     176                        } catch (NotSupportedException nse) { 
     177                            Log.LogDebug<HttpWebService<TRequestType>>("Caught NotSupportedException on Result.GetResponseStream(): {0}", nse.Message); 
     178                        } catch (WebException we) { 
     179                            Log.LogDebug<HttpWebService<TRequestType>>("Caught WebException on Result.GetResponseStream(): {0}", we.Message); 
     180                        } catch (Exception e) { 
     181                            Log.LogDebug<HttpWebService<TRequestType>>("Caught Exception on Result.GetResponseStream(): {0}", e.Message); 
     182                        } 
     183                        if (stream != null) { 
     184                            Async<String> responseObject = null; 
     185                            try { 
     186                                responseObject = stream.ReadToEndAsync<String>().ExecuteAsync<String>(); 
     187                            } catch (Exception e) { 
     188                                //TODO: Add the failed task to a retry queue. 
     189                                Log.LogDebug<HttpWebService<TRequestType>>("The call to stream.ReadToEndAsync<String>().ExecuteAsync<String>() for {0} failed with the error: {1}.", task.TaskID, e.Message); 
     190                            } 
     191 
     192                            string result = String.Empty; 
     193 
     194                            if (responseObject != null) { 
     195                                yield return responseObject; 
     196                                result = responseObject.Result; 
     197                            } 
     198 
     199                            task.Response.Response = result; 
     200                        } 
     201                    } else { 
     202                        Log.LogDebug<HttpWebService<TRequestType>>("Task {0} has failed. Need to add to to new queue to be reprocessed.", task.TaskID); 
     203                        //TODO: Add the failed task to a retry queue. 
     204                    } 
     205                } 
     206            } else { 
     207                Log.LogDebug<HttpWebService<TRequestType>>("Task {0} has failed. Need to add to to new queue to be reprocessed.", task.TaskID); 
     208                //TODO: Add the failed task to a retry queue. 
     209            } 
     210        } 
     211 
     212        public static IEnumerable<IAsync> CallWebService(ITask task, HttpRequestSettings settings) { 
     213 
     214            WebServiceType type = settings.WebServiceType; 
     215 
     216            HttpWebRequest request = null; 
     217            try { 
     218                request = (HttpWebRequest)WebRequest.Create(AWS_URI_ENDPOINT); 
     219                request.Timeout = settings.Timeout; 
     220                request.KeepAlive = settings.KeepAlive; 
     221                request.Pipelined = settings.Pipelined; 
     222                request.Method = settings.Method; 
     223                request.ContentType = settings.ContentType; 
     224            } catch (UriFormatException ufe) { 
     225                Log.LogInfo<HttpWebService<TRequestType>>("Caught UriFormatException on WebRequest.Create: {0}", ufe.Message); 
     226            } 
     227            IRequest webServiceRequest = task.Request; 
     228            byte[] buffer = null; 
     229 
     230            switch (type) { 
     231                case WebServiceType.REST: 
     232                    break; 
     233                case WebServiceType.SOAP: 
     234                    StringBuilder output = new StringBuilder(); 
     235                    //output.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
     236                    using (XmlReader xreader = CreateSoapMessage(task, LabelAttribute.FromMember(webServiceRequest.RequestType)).CreateReader()) { 
     237                        while (xreader.Read()) { 
     238                            if (xreader.IsStartElement()) { 
     239                                output.Append(xreader.ReadOuterXml()); 
     240                            } 
     241                        } 
     242                    } 
     243                    string soapMessage = output.ToString(); 
     244                    webServiceRequest.RequestMessage = soapMessage; 
     245                    buffer = m_encoding.GetBytes(soapMessage); 
     246                     
     247                    break; 
     248            } 
     249 
     250            int contentLength = buffer.Length; 
     251            request.ContentLength = contentLength; 
     252 
     253            foreach (KeyValuePair<string, string> header in webServiceRequest.Headers) { 
     254                request.Headers.Add(header.Key, header.Value); 
     255            } 
     256 
     257            Stream webStream = null; 
     258 
     259            try { 
     260                webStream = request.GetRequestStream(); 
     261            } catch (WebException we) { 
     262                Log.LogInfo<HttpWebService<TRequestType>>("Caught WebException on GetResponseAsync: {0}", we.Message); 
     263            } 
     264            if (webStream != null) { 
     265                using (webStream) { 
     266                    webStream.Write(buffer, 0, contentLength); 
     267                    Log.LogInfo<HttpWebService<TRequestType>>("Sending request for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
     268 
     269                    Async<WebResponse> response = null; 
     270                    try { 
     271                        response = request.GetResponseAsync(); 
     272                        Log.LogInfo<HttpWebService<TRequestType>>("Received response for task {0} on thread: {1}", task.TaskID, Thread.CurrentThread.ManagedThreadId); 
     273                    } catch (WebException we) { 
     274                        Log.LogDebug<HttpWebService<TRequestType>>("The call to GetResponseAsync for {0} failed with the error: {1}.", task.TaskID, we.Message); 
     275                        //TODO: Add the failed task to a retry queue. 
     276                    } 
     277                    if (response != null) { 
     278                        yield return response; 
     279                        Stream stream = null; 
     280                        try { 
     281                            stream = response.Result.GetResponseStream(); 
     282                        } catch (NotSupportedException nse) { 
     283                            Log.LogDebug<HttpWebService<TRequestType>>("Caught NotSupportedException on Result.GetResponseStream(): {0}", nse.Message); 
     284                        } catch (WebException we) { 
     285                            Log.LogDebug<HttpWebService<TRequestType>>("Caught WebException on Result.GetResponseStream(): {0}", we.Message); 
     286                        } catc