コード例 #1
0
        private static void SetRequestContent(HttpWebRequest webRequest,
                                              ServiceRequest serviceRequest)
        {
            var data = serviceRequest.BuildRequestContent();

            if (data == null ||
                (serviceRequest.Method != HttpMethod.Put &&
                 serviceRequest.Method != HttpMethod.Post))
            {
                // Skip setting content body in this case.
                webRequest.ContentLength = 0;
                return;
            }

            // Write data to the request stream.
            long userSetContentLength = -1;

            if (serviceRequest.Headers.ContainsKey(HttpHeaders.ContentLength))
            {
                userSetContentLength = long.Parse(serviceRequest.Headers[HttpHeaders.ContentLength]);
            }

            long streamLength = data.Length - data.Position;

            webRequest.ContentLength = (userSetContentLength >= 0 && userSetContentLength <= streamLength) ?
                                       userSetContentLength : streamLength;

            //webRequest.
            //webRequest.KeepAlive = true;
            //webRequest.ReadWriteTimeout = 100000000;
            //webRequest.ServicePoint.ConnectionLimit = 100000;
            //webRequest.Timeout = Configuration
            using (var requestStream = webRequest.GetRequestStream())
            {
                data.WriteTo(requestStream, webRequest.ContentLength);
                data.Seek(0, SeekOrigin.Begin);
            }
        }
コード例 #2
0
 protected abstract ServiceResponse SendCore(ServiceRequest request, ExecutionContext context);