System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply C# (CSharp) Method

InternalReply() protected method

protected InternalReply ( Message msg, TimeSpan timeout ) : void
msg Message
timeout TimeSpan
return void
		protected virtual void InternalReply (Message msg, TimeSpan timeout)
		{
			if (msg == null)
				throw new ArgumentNullException ("msg");

			MemoryStream ms = new MemoryStream ();
			Channel.Encoder.WriteMessage (msg, ms);
			Context.Response.ContentType = Channel.Encoder.ContentType;

			string pname = HttpResponseMessageProperty.Name;
			bool suppressEntityBody = false;
			if (msg.Properties.ContainsKey (pname)) {
				HttpResponseMessageProperty hp = (HttpResponseMessageProperty) msg.Properties [pname];
				string contentType = hp.Headers ["Content-Type"];
				if (contentType != null)
					Context.Response.ContentType = contentType;
				Context.Response.Headers.Add (hp.Headers);
				if (hp.StatusCode != default (HttpStatusCode))
					Context.Response.StatusCode = (int) hp.StatusCode;
				Context.Response.StatusDescription = hp.StatusDescription;
				if (hp.SuppressEntityBody)
					suppressEntityBody = true;
			}
			if (msg.IsFault)
				Context.Response.StatusCode = 500;
			if (!suppressEntityBody) {
				Context.Response.SetLength (ms.Length);
				Context.Response.OutputStream.Write (ms.GetBuffer (), 0, (int) ms.Length);
				Context.Response.OutputStream.Flush ();
			}
			else
				Context.Response.SuppressContent = true;
		}
	}