public override void Write(byte[] buffer, int offset, int size) { if (this.disposed) { throw new ObjectDisposedException(null); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset"); } if (size < 0) { throw new ArgumentOutOfRangeException("size"); } if (size + offset > buffer.Length) { throw new ArgumentException(XmlaSR.InvalidArgument, "buffer"); } try { if (size > 0) { if (this.dimeWriter == null) { this.dimeWriter = new DimeWriter(this.bufferedStream); this.dimeWriter.DefaultChunkSize = this.dimeChunkSize; this.dimeWriter.Options = base.GetTransportCapabilities(); this.dimeRecordForWrite = this.dimeWriter.CreateRecord(null, DataTypes.GetDataTypeFromEnum(this.GetRequestDataType()), TypeFormatEnum.MediaType, -1); if (TcpStream.TRACESWITCH.TraceVerbose) { StackTrace stackTrace = new StackTrace(); stackTrace.GetFrame(1).GetMethod(); } } this.dimeRecordForWrite.WriteBody(buffer, offset, size); } } catch (XmlaStreamException) { throw; } catch (IOException innerException) { throw new XmlaStreamException(innerException); } catch (SocketException innerException2) { throw new XmlaStreamException(innerException2); } }
private void GetRequestStream() { if (this.httpRequestStream == null) { this.httpRequest = (HttpWebRequest)WebRequest.Create(this.webSite); this.httpRequest.ServicePoint.SetTcpKeepAlive(true, 30000, 30000); this.httpRequest.Method = "POST"; this.httpRequest.Credentials = this.credentials; this.httpRequest.AllowAutoRedirect = this.allowAutoRedirect; this.httpRequest.UserAgent = "ADOMD.NET"; this.httpRequest.ContentType = DataTypes.GetDataTypeFromEnum(this.GetRequestDataType()); this.httpRequest.SendChunked = true; this.httpRequest.KeepAlive = true; this.httpRequest.UnsafeAuthenticatedConnectionSharing = true; this.httpRequest.ConnectionGroupName = this.connectionSecureGroupName; this.httpRequest.AutomaticDecompression = (this.acceptCompressedResponses ? DecompressionMethods.GZip : DecompressionMethods.None); this.httpRequest.Timeout = this.timeoutMs; this.httpRequest.CookieContainer = this.cookieContainer; if (this.clientCertificate != null) { this.httpRequest.ClientCertificates.Add(this.clientCertificate); } if (!this.hasASAzureHeaders && this.soapAction != null) { this.httpRequest.Headers.Add(this.soapAction); } this.httpRequest.Headers.Add(this.hasASAzureHeaders ? "x-ms-xmlacaps-negotiation-flags" : "X-Transport-Caps-Negotiation-Flags", base.GetTransportCapabilitiesString()); if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.applicationName)) { this.httpRequest.Headers.Add("SspropInitAppName", this.applicationName); } if (!string.IsNullOrEmpty(base.SessionID)) { this.httpRequest.Headers.Add(this.hasASAzureHeaders ? "x-ms-xmlasession-id" : "X-AS-SessionID", base.SessionID); } if (!this.hasASAzureHeaders && base.IsSessionTokenNeeded) { this.httpRequest.Headers.Add("X-AS-GetSessionToken", true.ToString()); } else { this.httpRequest.Headers.Remove("X-AS-GetSessionToken"); } if (!this.IsInternalASAzure && !object.Equals(this.ActivityID, Guid.Empty)) { this.httpRequest.Headers.Add(this.hasASAzureHeaders ? "x-ms-parent-activity-id" : "X-AS-ActivityID", this.ActivityID.ToString()); } if (!this.hasASAzureHeaders && !object.Equals(this.RequestID, Guid.Empty)) { this.httpRequest.Headers.Add("X-AS-RequestID", this.RequestID.ToString()); } if (!this.hasASAzureHeaders && !object.Equals(this.CurrentActivityID, Guid.Empty)) { this.httpRequest.Headers.Add("X-AS-CurrentActivityID", this.CurrentActivityID.ToString()); } if (!string.IsNullOrEmpty(this.authorizationHeader)) { this.httpRequest.Headers.Add("Authorization", this.authorizationHeader); } else if (this.aadTokenHolder != null) { this.httpRequest.Headers.Add("Authorization", "Bearer " + this.aadTokenHolder.GetValidAccessToken()); } if (this.IsASAzure) { if (!this.hasASAzureHeaders) { throw new ArgumentOutOfRangeException("hasASAzureHeaders"); } if (string.IsNullOrEmpty(this.xmlaServerHeader)) { throw new ArgumentOutOfRangeException("xmlaServerHeader"); } this.httpRequest.Headers.Add("x-ms-xmlaserver", this.xmlaServerHeader); } if (this.IsASAzure) { string generalInfoHeaderValue = ASAzureUtility.GetGeneralInfoHeaderValue(this.connectionInfo.UseAdalCache, this.connectionInfo.UserID); this.httpRequest.Headers.Add("x-ms-xmlaapp-general-info", generalInfoHeaderValue); } if (this.IsInternalASAzure) { if (this.ParentActivityID == Guid.Empty) { throw new ArgumentNullException(string.Format("{0} not set on call context for internal AS Azure usage.", "x-ms-parent-activity-id")); } if (this.RootActivityID == Guid.Empty) { throw new ArgumentNullException(string.Format("{0} not set on call context for internal AS Azure usage.", "x-ms-root-activity-id")); } this.httpRequest.Headers.Add("x-ms-root-activity-id", this.RootActivityID.ToString()); this.httpRequest.Headers.Add("x-ms-parent-activity-id", this.ParentActivityID.ToString()); } if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.authorizedUserName)) { this.httpRequest.Headers.Add("X-AS-AuthorizedUserName", this.authorizedUserName); } if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.authorizedUserID)) { this.httpRequest.Headers.Add("X-AS-AuthorizedUserID", this.authorizedUserID); } if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.authorizedUserTenant)) { this.httpRequest.Headers.Add("X-AS-AuthorizedUserTenant", this.authorizedUserTenant); } if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.asdbAccessToken)) { this.httpRequest.Headers.Add("X-SAAS-DatabaseAccessToken", this.asdbAccessToken); } if (!this.hasASAzureHeaders && !string.IsNullOrEmpty(this.RoutingToken)) { this.httpRequest.Headers.Add("X-AS-Routing", this.RoutingToken); } this.httpRequestStream = new BufferedStream(this.httpRequest.GetRequestStream(), XmlaClient.HttpStreamBufferSize); } }