private Stream GetNonFileStream(Uri uri, ICredentials credentials)
        {
            WebRequest req = WebRequest.Create(uri);

            if (credentials != null)
            {
                req.Credentials = credentials;
            }
            WebResponse resp = req.GetResponse();

            if (req is HttpWebRequest)
            {
                HttpWebRequest req1 = (HttpWebRequest)req;
                lock (_connections) {
                    XmlWebConnectionLimit limit = (XmlWebConnectionLimit)_connections[req1.Address.Host];
                    if (limit == null)
                    {
                        limit = new XmlWebConnectionLimit(req1.ServicePoint.ConnectionLimit);
                        _connections.Add(req1.Address.Host, limit);
                    }
                    limit.Limit++;
                    req1.ServicePoint.ConnectionLimit = limit.Limit;
                }
                return(new XmlEntityStream(resp.GetResponseStream(), this, req1.Address));
            }
            else
            {
                return(resp.GetResponseStream());
            }
        }
 internal void Remove(XmlEntityStream stream)
 {
     lock (_connections) {
         XmlWebConnectionLimit limit = (XmlWebConnectionLimit)_connections[stream.Uri.Host];
         if (limit != null)
         {
             limit.Limit--;
             if (limit.Limit <= limit.OriginalLimit)
             {
                 _connections.Remove(stream.Uri.Host);
             }
         }
     }
 }
Exemplo n.º 3
0
 private Stream GetNonFileStream(Uri uri, ICredentials credentials) {
     WebRequest req = WebRequest.Create(uri);
     if (credentials != null) {
         req.Credentials = credentials;
     }
     WebResponse resp = req.GetResponse();
     if (req is HttpWebRequest) {
         HttpWebRequest req1 = (HttpWebRequest)req;
         lock (_connections) {
             XmlWebConnectionLimit limit = (XmlWebConnectionLimit)_connections[req1.Address.Host];
             if (limit == null) {
                 limit = new XmlWebConnectionLimit(req1.ServicePoint.ConnectionLimit);
                 _connections.Add(req1.Address.Host, limit);
             }
             limit.Limit++;
             req1.ServicePoint.ConnectionLimit = limit.Limit;
         }
         return new XmlEntityStream(resp.GetResponseStream(), this, req1.Address);
     }
     else {
         return resp.GetResponseStream();
     }
 }