You've already forked linux-packaging-mono
Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
234
external/referencesource/System.ServiceModel.Web/System/ServiceModel/Channels/HttpStreamMessage.cs
vendored
Normal file
234
external/referencesource/System.ServiceModel.Web/System/ServiceModel/Channels/HttpStreamMessage.cs
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable 1634 // Stops compiler from warning about unknown warnings (for Presharp)
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel;
|
||||
using System.Xml;
|
||||
using DiagnosticUtility = System.ServiceModel.DiagnosticUtility;
|
||||
|
||||
class HttpStreamMessage : Message
|
||||
{
|
||||
internal const string StreamElementName = "Binary";
|
||||
BodyWriter bodyWriter;
|
||||
MessageHeaders headers;
|
||||
MessageProperties properties;
|
||||
|
||||
public HttpStreamMessage(BodyWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
|
||||
}
|
||||
this.bodyWriter = writer;
|
||||
this.headers = new MessageHeaders(MessageVersion.None, 1);
|
||||
this.properties = new MessageProperties();
|
||||
}
|
||||
|
||||
public HttpStreamMessage(MessageHeaders headers, MessageProperties properties, BodyWriter bodyWriter)
|
||||
{
|
||||
if (bodyWriter == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bodyWriter");
|
||||
}
|
||||
this.headers = new MessageHeaders(headers);
|
||||
this.properties = new MessageProperties(properties);
|
||||
this.bodyWriter = bodyWriter;
|
||||
}
|
||||
|
||||
public override MessageHeaders Headers
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
#pragma warning suppress 56503
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateDisposedException());
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsFault
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override MessageProperties Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
#pragma warning suppress 56503
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateDisposedException());
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
||||
public override MessageVersion Version
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
#pragma warning suppress 56503
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateDisposedException());
|
||||
}
|
||||
return MessageVersion.None;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBodyToString(XmlDictionaryWriter writer)
|
||||
{
|
||||
if (this.bodyWriter.IsBuffered)
|
||||
{
|
||||
bodyWriter.WriteBodyContents(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteString(SR2.GetString(SR2.MessageBodyIsStream));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
base.OnClose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
ex = e;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (properties != null)
|
||||
{
|
||||
properties.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
if (ex == null)
|
||||
{
|
||||
ex = e;
|
||||
}
|
||||
}
|
||||
|
||||
if (ex != null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex);
|
||||
}
|
||||
|
||||
this.bodyWriter = null;
|
||||
}
|
||||
|
||||
protected override MessageBuffer OnCreateBufferedCopy(int maxBufferSize)
|
||||
{
|
||||
BodyWriter bufferedBodyWriter;
|
||||
if (this.bodyWriter.IsBuffered)
|
||||
{
|
||||
bufferedBodyWriter = this.bodyWriter;
|
||||
}
|
||||
else
|
||||
{
|
||||
bufferedBodyWriter = this.bodyWriter.CreateBufferedCopy(maxBufferSize);
|
||||
}
|
||||
return new HttpStreamMessageBuffer(this.Headers, new MessageProperties(this.Properties), bufferedBodyWriter);
|
||||
}
|
||||
|
||||
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
|
||||
{
|
||||
this.bodyWriter.WriteBodyContents(writer);
|
||||
}
|
||||
|
||||
Exception CreateDisposedException()
|
||||
{
|
||||
return new ObjectDisposedException("", SR2.GetString(SR2.MessageClosed));
|
||||
}
|
||||
|
||||
class HttpStreamMessageBuffer : MessageBuffer
|
||||
{
|
||||
BodyWriter bodyWriter;
|
||||
bool closed;
|
||||
MessageHeaders headers;
|
||||
MessageProperties properties;
|
||||
object thisLock = new object();
|
||||
|
||||
public HttpStreamMessageBuffer(MessageHeaders headers,
|
||||
MessageProperties properties, BodyWriter bodyWriter)
|
||||
: base()
|
||||
{
|
||||
this.bodyWriter = bodyWriter;
|
||||
this.headers = headers;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public override int BufferSize
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
object ThisLock
|
||||
{
|
||||
get { return thisLock; }
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
lock (ThisLock)
|
||||
{
|
||||
if (!closed)
|
||||
{
|
||||
closed = true;
|
||||
bodyWriter = null;
|
||||
headers = null;
|
||||
properties = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Message CreateMessage()
|
||||
{
|
||||
lock (ThisLock)
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateDisposedException());
|
||||
}
|
||||
return new HttpStreamMessage(this.headers, this.properties, this.bodyWriter);
|
||||
}
|
||||
}
|
||||
|
||||
Exception CreateDisposedException()
|
||||
{
|
||||
return new ObjectDisposedException("", SR2.GetString(SR2.MessageBufferIsClosed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System.Net;
|
||||
|
||||
public sealed class JavascriptCallbackResponseMessageProperty
|
||||
{
|
||||
static readonly string JavascriptCallbackResponseMessagePropertyName = "javascriptCallbackResponse";
|
||||
|
||||
public JavascriptCallbackResponseMessageProperty()
|
||||
{
|
||||
}
|
||||
|
||||
public static string Name
|
||||
{
|
||||
get { return JavascriptCallbackResponseMessagePropertyName; }
|
||||
}
|
||||
|
||||
public string CallbackFunctionName { get; set; }
|
||||
|
||||
public HttpStatusCode? StatusCode { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,191 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
class JavascriptXmlWriterWrapper : XmlDictionaryWriter
|
||||
{
|
||||
Encoding encoding;
|
||||
Stream stream;
|
||||
XmlDictionaryWriter xmlJsonWriter;
|
||||
byte[] encodedClosingFunctionCall;
|
||||
|
||||
public JavascriptXmlWriterWrapper(Encoding encoding)
|
||||
{
|
||||
this.encoding = encoding;
|
||||
this.encodedClosingFunctionCall = this.encoding.GetBytes(");");
|
||||
}
|
||||
|
||||
public JavascriptCallbackResponseMessageProperty JavascriptResponseMessageProperty
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public XmlDictionaryWriter XmlJsonWriter
|
||||
{
|
||||
get { return this.xmlJsonWriter; }
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
this.xmlJsonWriter.Close();
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
this.xmlJsonWriter.Flush();
|
||||
}
|
||||
|
||||
public override string LookupPrefix(string ns)
|
||||
{
|
||||
return this.xmlJsonWriter.LookupPrefix(ns);
|
||||
}
|
||||
|
||||
public override void WriteBase64(byte[] buffer, int index, int count)
|
||||
{
|
||||
this.xmlJsonWriter.WriteBase64(buffer, index, count);
|
||||
}
|
||||
|
||||
public override void WriteCData(string text)
|
||||
{
|
||||
this.xmlJsonWriter.WriteCData(text);
|
||||
}
|
||||
|
||||
public override void WriteCharEntity(char ch)
|
||||
{
|
||||
this.xmlJsonWriter.WriteCharEntity(ch);
|
||||
}
|
||||
|
||||
public override void WriteChars(char[] buffer, int index, int count)
|
||||
{
|
||||
this.xmlJsonWriter.WriteChars(buffer, index, count);
|
||||
}
|
||||
|
||||
public override void WriteComment(string text)
|
||||
{
|
||||
this.xmlJsonWriter.WriteComment(text);
|
||||
}
|
||||
|
||||
public override void WriteDocType(string name, string pubid, string sysid, string subset)
|
||||
{
|
||||
this.xmlJsonWriter.WriteDocType(name, pubid, sysid, subset);
|
||||
}
|
||||
|
||||
public override void WriteEndAttribute()
|
||||
{
|
||||
this.xmlJsonWriter.WriteEndAttribute();
|
||||
}
|
||||
|
||||
public override void WriteEndDocument()
|
||||
{
|
||||
this.xmlJsonWriter.WriteEndDocument();
|
||||
|
||||
if (this.JavascriptResponseMessageProperty != null &&
|
||||
!String.IsNullOrEmpty(this.JavascriptResponseMessageProperty.CallbackFunctionName))
|
||||
{
|
||||
this.xmlJsonWriter.Flush();
|
||||
if (this.JavascriptResponseMessageProperty.StatusCode != null && (int)this.JavascriptResponseMessageProperty.StatusCode != 200)
|
||||
{
|
||||
byte[] buffer = this.encoding.GetBytes(String.Format(CultureInfo.InvariantCulture, ",{0}", (int)this.JavascriptResponseMessageProperty.StatusCode));
|
||||
this.stream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
this.stream.Write(this.encodedClosingFunctionCall, 0, this.encodedClosingFunctionCall.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteEndElement()
|
||||
{
|
||||
this.xmlJsonWriter.WriteEndElement();
|
||||
}
|
||||
|
||||
public override void WriteEntityRef(string name)
|
||||
{
|
||||
this.xmlJsonWriter.WriteEntityRef(name);
|
||||
}
|
||||
|
||||
public override void WriteFullEndElement()
|
||||
{
|
||||
this.xmlJsonWriter.WriteFullEndElement();
|
||||
}
|
||||
|
||||
public override void WriteProcessingInstruction(string name, string text)
|
||||
{
|
||||
this.xmlJsonWriter.WriteProcessingInstruction(name, text);
|
||||
}
|
||||
|
||||
public override void WriteRaw(string data)
|
||||
{
|
||||
this.xmlJsonWriter.WriteRaw(data);
|
||||
}
|
||||
|
||||
public override void WriteRaw(char[] buffer, int index, int count)
|
||||
{
|
||||
this.xmlJsonWriter.WriteRaw(buffer, index, count);
|
||||
}
|
||||
|
||||
public override void WriteStartAttribute(string prefix, string localName, string ns)
|
||||
{
|
||||
this.xmlJsonWriter.WriteStartAttribute(prefix, localName, ns);
|
||||
}
|
||||
|
||||
public override void WriteStartDocument(bool standalone)
|
||||
{
|
||||
StartJsonMessage();
|
||||
this.xmlJsonWriter.WriteStartDocument(standalone);
|
||||
}
|
||||
|
||||
public override void WriteStartDocument()
|
||||
{
|
||||
StartJsonMessage();
|
||||
this.xmlJsonWriter.WriteStartDocument();
|
||||
}
|
||||
|
||||
void StartJsonMessage()
|
||||
{
|
||||
if (this.JavascriptResponseMessageProperty != null &&
|
||||
!String.IsNullOrEmpty(this.JavascriptResponseMessageProperty.CallbackFunctionName))
|
||||
{
|
||||
byte[] buffer = this.encoding.GetBytes(String.Format(CultureInfo.InvariantCulture, "{0}(", this.JavascriptResponseMessageProperty.CallbackFunctionName));
|
||||
this.stream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteStartElement(string prefix, string localName, string ns)
|
||||
{
|
||||
this.xmlJsonWriter.WriteStartElement(prefix, localName, ns);
|
||||
}
|
||||
|
||||
public override WriteState WriteState
|
||||
{
|
||||
get { return this.xmlJsonWriter.WriteState; }
|
||||
}
|
||||
|
||||
public override void WriteString(string text)
|
||||
{
|
||||
this.xmlJsonWriter.WriteString(text);
|
||||
}
|
||||
|
||||
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
|
||||
{
|
||||
this.xmlJsonWriter.WriteSurrogateCharEntity(lowChar, highChar);
|
||||
}
|
||||
|
||||
public override void WriteWhitespace(string ws)
|
||||
{
|
||||
this.xmlJsonWriter.WriteWhitespace(ws);
|
||||
}
|
||||
|
||||
public void SetOutput(Stream stream, XmlDictionaryWriter writer)
|
||||
{
|
||||
this.stream = stream;
|
||||
this.xmlJsonWriter = writer;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
class RawContentTypeMapper : WebContentTypeMapper
|
||||
{
|
||||
static readonly RawContentTypeMapper instance = new RawContentTypeMapper();
|
||||
|
||||
public static RawContentTypeMapper Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public override WebContentFormat GetMessageFormatForContentType(string contentType)
|
||||
{
|
||||
return WebContentFormat.Raw;
|
||||
}
|
||||
}
|
||||
}
|
206
external/referencesource/System.ServiceModel.Web/System/ServiceModel/Channels/StreamBodyWriter.cs
vendored
Normal file
206
external/referencesource/System.ServiceModel.Web/System/ServiceModel/Channels/StreamBodyWriter.cs
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel;
|
||||
using System.Xml;
|
||||
using DiagnosticUtility = System.ServiceModel.DiagnosticUtility;
|
||||
|
||||
public abstract class StreamBodyWriter : BodyWriter
|
||||
{
|
||||
// if isQuirkedTo40Behavior = true, does not try to write out <Binary> tags
|
||||
// this maintains compatibility for 4.0 implementers of a derived StreamBodyWriter if they
|
||||
// depended on behaviour where StreamBodyWriter isn't ByteStreamEncoder aware.
|
||||
// e.g., if they wrote their own <Binary> tags and relied on StreamBodyWriter to only write out the body.
|
||||
//
|
||||
// if isQuirkedTo40Behavior = false, XmlWriterBackedStream will write out <Binary> tags (default in 4.5)
|
||||
readonly bool isQuirkedTo40Behavior;
|
||||
|
||||
// externally accessible constructor quirked:
|
||||
// if version < 4.5, XmlWriterBackedStream does not try to write out <Binary> tags
|
||||
// if version >= 4.5, XmlWriterBackedStream will write out <Binary> tags
|
||||
protected StreamBodyWriter(bool isBuffered)
|
||||
: this(isBuffered, !OSEnvironmentHelper.IsApplicationTargeting45)
|
||||
{ }
|
||||
|
||||
// internally accessible constructor allows derived types to determine whether StreamBodyWriter should be ByteStream aware
|
||||
// internal implementations SHOULD use isQuirkedTo40Behavior = false.
|
||||
internal StreamBodyWriter(bool isBuffered, bool isQuirkedTo40Behavior)
|
||||
: base(isBuffered)
|
||||
{
|
||||
this.isQuirkedTo40Behavior = isQuirkedTo40Behavior;
|
||||
}
|
||||
|
||||
internal static StreamBodyWriter CreateStreamBodyWriter(Action<Stream> streamAction)
|
||||
{
|
||||
if (streamAction == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("actionOfStream");
|
||||
}
|
||||
return new ActionOfStreamBodyWriter(streamAction);
|
||||
}
|
||||
|
||||
protected abstract void OnWriteBodyContents(Stream stream);
|
||||
|
||||
protected override BodyWriter OnCreateBufferedCopy(int maxBufferSize)
|
||||
{
|
||||
using (BufferManagerOutputStream bufferedStream = new BufferManagerOutputStream(SR2.MaxReceivedMessageSizeExceeded, maxBufferSize))
|
||||
{
|
||||
this.OnWriteBodyContents(bufferedStream);
|
||||
int size;
|
||||
byte[] bytesArray = bufferedStream.ToArray(out size);
|
||||
return new BufferedBytesStreamBodyWriter(bytesArray, size);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
|
||||
{
|
||||
using (XmlWriterBackedStream stream = new XmlWriterBackedStream(writer, this.isQuirkedTo40Behavior))
|
||||
{
|
||||
OnWriteBodyContents(stream);
|
||||
}
|
||||
}
|
||||
|
||||
class XmlWriterBackedStream : Stream
|
||||
{
|
||||
private const string StreamElementName = "Binary";
|
||||
private readonly bool isQuirkedTo40Behavior;
|
||||
|
||||
XmlWriter writer;
|
||||
|
||||
public XmlWriterBackedStream(XmlWriter writer, bool isQuirkedTo40Behavior)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
|
||||
}
|
||||
this.writer = writer;
|
||||
|
||||
this.isQuirkedTo40Behavior = isQuirkedTo40Behavior;
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
this.writer.Flush();
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertyGetNotSupported, "Length")));
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertyGetNotSupported, "Position")));
|
||||
}
|
||||
set
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertySetNotSupported, "Position")));
|
||||
}
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "Read")));
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "BeginRead")));
|
||||
}
|
||||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "EndRead")));
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "ReadByte")));
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "Seek")));
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "SetLength")));
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (writer.WriteState == WriteState.Content || this.isQuirkedTo40Behavior)
|
||||
{
|
||||
// if isQuirkedTo40Behavior == true, maintains compatibility for 4.0 implementers of a derived StreamBodyWriter
|
||||
// if they depended on behaviour without state checks, e.g., if they wrote their own <Binary> tags
|
||||
this.writer.WriteBase64(buffer, offset, count);
|
||||
}
|
||||
else if (writer.WriteState == WriteState.Start)
|
||||
{
|
||||
writer.WriteStartElement(StreamElementName, string.Empty);
|
||||
this.writer.WriteBase64(buffer, offset, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BufferedBytesStreamBodyWriter : StreamBodyWriter
|
||||
{
|
||||
byte[] array;
|
||||
int size;
|
||||
|
||||
public BufferedBytesStreamBodyWriter(byte[] array, int size)
|
||||
: base(true, false)
|
||||
{
|
||||
this.array = array;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
protected override void OnWriteBodyContents(Stream stream)
|
||||
{
|
||||
stream.Write(this.array, 0, this.size);
|
||||
}
|
||||
}
|
||||
|
||||
class ActionOfStreamBodyWriter : StreamBodyWriter
|
||||
{
|
||||
Action<Stream> actionOfStream;
|
||||
|
||||
public ActionOfStreamBodyWriter(Action<Stream> actionOfStream)
|
||||
: base(false, false)
|
||||
{
|
||||
this.actionOfStream = actionOfStream;
|
||||
}
|
||||
|
||||
protected override void OnWriteBodyContents(Stream stream)
|
||||
{
|
||||
actionOfStream(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
using System.Globalization;
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
public sealed class WebBodyFormatMessageProperty : IMessageProperty
|
||||
{
|
||||
WebContentFormat format;
|
||||
static WebBodyFormatMessageProperty jsonProperty;
|
||||
public const string Name = "WebBodyFormatMessageProperty";
|
||||
static WebBodyFormatMessageProperty xmlProperty;
|
||||
static WebBodyFormatMessageProperty rawProperty;
|
||||
|
||||
public WebBodyFormatMessageProperty(WebContentFormat format)
|
||||
{
|
||||
if (format == WebContentFormat.Default)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR2.GetString(SR2.DefaultContentFormatNotAllowedInProperty)));
|
||||
}
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public WebContentFormat Format
|
||||
{
|
||||
get { return this.format; }
|
||||
}
|
||||
|
||||
internal static WebBodyFormatMessageProperty JsonProperty
|
||||
{
|
||||
get
|
||||
{
|
||||
if (jsonProperty == null)
|
||||
{
|
||||
jsonProperty = new WebBodyFormatMessageProperty(WebContentFormat.Json);
|
||||
}
|
||||
return jsonProperty;
|
||||
}
|
||||
}
|
||||
|
||||
internal static WebBodyFormatMessageProperty XmlProperty
|
||||
{
|
||||
get
|
||||
{
|
||||
if (xmlProperty == null)
|
||||
{
|
||||
xmlProperty = new WebBodyFormatMessageProperty(WebContentFormat.Xml);
|
||||
}
|
||||
return xmlProperty;
|
||||
}
|
||||
}
|
||||
|
||||
internal static WebBodyFormatMessageProperty RawProperty
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rawProperty == null)
|
||||
{
|
||||
rawProperty = new WebBodyFormatMessageProperty(WebContentFormat.Raw);
|
||||
}
|
||||
return rawProperty;
|
||||
}
|
||||
}
|
||||
|
||||
public IMessageProperty CreateCopy()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, SR2.GetString(SR2.WebBodyFormatPropertyToString, this.Format.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
public enum WebContentFormat
|
||||
{
|
||||
Default,
|
||||
Xml,
|
||||
Json,
|
||||
Raw
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
internal static class WebContentFormatHelper
|
||||
{
|
||||
internal static bool IsDefined(WebContentFormat format)
|
||||
{
|
||||
return (format == WebContentFormat.Default
|
||||
|| format == WebContentFormat.Xml
|
||||
|| format == WebContentFormat.Json
|
||||
|| format == WebContentFormat.Raw);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
public abstract class WebContentTypeMapper
|
||||
{
|
||||
public abstract WebContentFormat GetMessageFormatForContentType(string contentType);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System.ServiceModel;
|
||||
|
||||
static class WebHttpBindingDefaults
|
||||
{
|
||||
internal const TransferMode TransferMode = System.ServiceModel.TransferMode.Buffered;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,299 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System.ServiceModel;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.ServiceModel.Administration;
|
||||
using System.ServiceModel.Description;
|
||||
|
||||
public sealed class WebMessageEncodingBindingElement : MessageEncodingBindingElement, IWsdlExportExtension, IWmiInstanceProvider
|
||||
{
|
||||
WebContentTypeMapper contentTypeMapper;
|
||||
|
||||
int maxReadPoolSize;
|
||||
int maxWritePoolSize;
|
||||
XmlDictionaryReaderQuotas readerQuotas;
|
||||
Encoding writeEncoding;
|
||||
|
||||
public WebMessageEncodingBindingElement()
|
||||
: this(TextEncoderDefaults.Encoding)
|
||||
{
|
||||
}
|
||||
|
||||
public WebMessageEncodingBindingElement(Encoding writeEncoding)
|
||||
{
|
||||
if (writeEncoding == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writeEncoding");
|
||||
}
|
||||
|
||||
TextEncoderDefaults.ValidateEncoding(writeEncoding);
|
||||
this.maxReadPoolSize = EncoderDefaults.MaxReadPoolSize;
|
||||
this.maxWritePoolSize = EncoderDefaults.MaxWritePoolSize;
|
||||
this.readerQuotas = new XmlDictionaryReaderQuotas();
|
||||
EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas);
|
||||
this.writeEncoding = writeEncoding;
|
||||
}
|
||||
|
||||
WebMessageEncodingBindingElement(WebMessageEncodingBindingElement elementToBeCloned)
|
||||
: base(elementToBeCloned)
|
||||
{
|
||||
this.maxReadPoolSize = elementToBeCloned.maxReadPoolSize;
|
||||
this.maxWritePoolSize = elementToBeCloned.maxWritePoolSize;
|
||||
this.readerQuotas = new XmlDictionaryReaderQuotas();
|
||||
elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas);
|
||||
this.writeEncoding = elementToBeCloned.writeEncoding;
|
||||
this.contentTypeMapper = elementToBeCloned.contentTypeMapper;
|
||||
this.CrossDomainScriptAccessEnabled = elementToBeCloned.CrossDomainScriptAccessEnabled;
|
||||
}
|
||||
public WebContentTypeMapper ContentTypeMapper
|
||||
{
|
||||
get
|
||||
{
|
||||
return contentTypeMapper;
|
||||
}
|
||||
set
|
||||
{
|
||||
contentTypeMapper = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxReadPoolSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.maxReadPoolSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
|
||||
SR2.GetString(SR2.ValueMustBePositive)));
|
||||
}
|
||||
this.maxReadPoolSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxWritePoolSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.maxWritePoolSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
|
||||
SR2.GetString(SR2.ValueMustBePositive)));
|
||||
}
|
||||
this.maxWritePoolSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override MessageVersion MessageVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return MessageVersion.None;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
|
||||
if (value != MessageVersion.None)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR2.GetString(SR2.JsonOnlySupportsMessageVersionNone));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal override bool IsWsdlExportable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public XmlDictionaryReaderQuotas ReaderQuotas
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.readerQuotas;
|
||||
}
|
||||
}
|
||||
|
||||
public Encoding WriteEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.writeEncoding;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
|
||||
TextEncoderDefaults.ValidateEncoding(value);
|
||||
this.writeEncoding = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CrossDomainScriptAccessEnabled
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalBuildChannelFactory<TChannel>(context);
|
||||
}
|
||||
|
||||
public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalBuildChannelListener<TChannel>(context);
|
||||
}
|
||||
|
||||
public override bool CanBuildChannelListener<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalCanBuildChannelListener<TChannel>(context);
|
||||
}
|
||||
|
||||
public override BindingElement Clone()
|
||||
{
|
||||
return new WebMessageEncodingBindingElement(this);
|
||||
}
|
||||
|
||||
public override MessageEncoderFactory CreateMessageEncoderFactory()
|
||||
{
|
||||
return new WebMessageEncoderFactory(this.WriteEncoding, this.MaxReadPoolSize, this.MaxWritePoolSize, this.ReaderQuotas, this.ContentTypeMapper, this.CrossDomainScriptAccessEnabled);
|
||||
}
|
||||
|
||||
public override T GetProperty<T>(BindingContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
|
||||
}
|
||||
if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
|
||||
{
|
||||
return (T)(object) this.readerQuotas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.GetProperty<T>(context);
|
||||
}
|
||||
}
|
||||
|
||||
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
|
||||
{
|
||||
wmiInstance.SetProperty(AdministrationStrings.MessageVersion, this.MessageVersion.ToString());
|
||||
wmiInstance.SetProperty(AdministrationStrings.Encoding, this.writeEncoding.WebName);
|
||||
wmiInstance.SetProperty(AdministrationStrings.MaxReadPoolSize, this.maxReadPoolSize);
|
||||
wmiInstance.SetProperty(AdministrationStrings.MaxWritePoolSize, this.maxWritePoolSize);
|
||||
if (this.ReaderQuotas != null)
|
||||
{
|
||||
IWmiInstance readerQuotasInstance = wmiInstance.NewInstance(AdministrationStrings.XmlDictionaryReaderQuotas);
|
||||
readerQuotasInstance.SetProperty(AdministrationStrings.MaxArrayLength, this.readerQuotas.MaxArrayLength);
|
||||
readerQuotasInstance.SetProperty(AdministrationStrings.MaxBytesPerRead, this.readerQuotas.MaxBytesPerRead);
|
||||
readerQuotasInstance.SetProperty(AdministrationStrings.MaxDepth, this.readerQuotas.MaxDepth);
|
||||
readerQuotasInstance.SetProperty(AdministrationStrings.MaxNameTableCharCount, this.readerQuotas.MaxNameTableCharCount);
|
||||
readerQuotasInstance.SetProperty(AdministrationStrings.MaxStringContentLength, this.readerQuotas.MaxStringContentLength);
|
||||
wmiInstance.SetProperty(AdministrationStrings.ReaderQuotas, readerQuotasInstance);
|
||||
}
|
||||
}
|
||||
|
||||
string IWmiInstanceProvider.GetInstanceType()
|
||||
{
|
||||
return typeof(WebMessageEncodingBindingElement).Name;
|
||||
}
|
||||
|
||||
void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
|
||||
{
|
||||
}
|
||||
|
||||
void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
|
||||
}
|
||||
|
||||
SoapHelper.SetSoapVersion(context, exporter, this.MessageVersion.Envelope);
|
||||
}
|
||||
|
||||
internal override bool CheckEncodingVersion(EnvelopeVersion version)
|
||||
{
|
||||
return MessageVersion.Envelope == version;
|
||||
}
|
||||
|
||||
internal override bool IsMatch(BindingElement b)
|
||||
{
|
||||
if (!base.IsMatch(b))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
WebMessageEncodingBindingElement other = b as WebMessageEncodingBindingElement;
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.maxReadPoolSize != other.MaxReadPoolSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.maxWritePoolSize != other.MaxWritePoolSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// compare XmlDictionaryReaderQuotas
|
||||
if (this.readerQuotas.MaxStringContentLength != other.ReaderQuotas.MaxStringContentLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.readerQuotas.MaxArrayLength != other.ReaderQuotas.MaxArrayLength)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.readerQuotas.MaxBytesPerRead != other.ReaderQuotas.MaxBytesPerRead)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.readerQuotas.MaxDepth != other.ReaderQuotas.MaxDepth)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.readerQuotas.MaxNameTableCharCount != other.ReaderQuotas.MaxNameTableCharCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.WriteEncoding.EncodingName != other.WriteEncoding.EncodingName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this.MessageVersion.IsMatch(other.MessageVersion))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ContentTypeMapper != other.ContentTypeMapper)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable 1634 // Stops compiler from warning about unknown warnings (for Presharp)
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Description;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Runtime.Serialization;
|
||||
using DiagnosticUtility = System.ServiceModel.DiagnosticUtility;
|
||||
using System.IO;
|
||||
|
||||
class WebScriptMetadataMessage : BodyWriterMessage
|
||||
{
|
||||
const string proxyContentTag = "JavaScriptProxy";
|
||||
string proxyContent;
|
||||
|
||||
public WebScriptMetadataMessage(string action, string proxyContent) : base(MessageVersion.None, action, new WebScriptMetadataBodyWriter(proxyContent))
|
||||
{
|
||||
this.proxyContent = proxyContent;
|
||||
}
|
||||
|
||||
protected override void OnBodyToString(XmlDictionaryWriter writer)
|
||||
{
|
||||
writer.WriteStartElement(proxyContentTag);
|
||||
writer.WriteCData(proxyContent);
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
class WebScriptMetadataBodyWriter : BodyWriter
|
||||
{
|
||||
string proxyContent;
|
||||
|
||||
public WebScriptMetadataBodyWriter(string proxyContent)
|
||||
: base(true)
|
||||
{
|
||||
this.proxyContent = proxyContent;
|
||||
}
|
||||
|
||||
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
|
||||
{
|
||||
writer.WriteRaw(proxyContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System.IO;
|
||||
using System.ServiceModel.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using WebTD = System.ServiceModel.Web.Diagnostics.Application.TD;
|
||||
|
||||
|
||||
class WebScriptMetadataMessageEncoderFactory : MessageEncoderFactory
|
||||
{
|
||||
const string applicationJavaScriptMediaType = "application/x-javascript";
|
||||
WebScriptMetadataMessageEncoder messageEncoder;
|
||||
|
||||
public WebScriptMetadataMessageEncoderFactory(XmlDictionaryReaderQuotas quotas)
|
||||
{
|
||||
messageEncoder = new WebScriptMetadataMessageEncoder(quotas);
|
||||
}
|
||||
|
||||
public override MessageEncoder Encoder
|
||||
{
|
||||
get { return messageEncoder; }
|
||||
}
|
||||
|
||||
public override MessageVersion MessageVersion
|
||||
{
|
||||
get { return messageEncoder.MessageVersion; }
|
||||
}
|
||||
|
||||
class WebScriptMetadataMessageEncoder : MessageEncoder
|
||||
{
|
||||
static UTF8Encoding UTF8EncodingWithoutByteOrderMark = new UTF8Encoding(false);
|
||||
string contentType;
|
||||
MessageEncoder innerReadMessageEncoder;
|
||||
string mediaType;
|
||||
XmlDictionaryReaderQuotas readerQuotas;
|
||||
|
||||
public WebScriptMetadataMessageEncoder(XmlDictionaryReaderQuotas quotas)
|
||||
{
|
||||
this.readerQuotas = new XmlDictionaryReaderQuotas();
|
||||
quotas.CopyTo(this.readerQuotas);
|
||||
this.mediaType = this.contentType = applicationJavaScriptMediaType;
|
||||
this.innerReadMessageEncoder = new TextMessageEncodingBindingElement(MessageVersion.None, Encoding.UTF8).CreateMessageEncoderFactory().Encoder;
|
||||
}
|
||||
|
||||
public override string ContentType
|
||||
{
|
||||
get { return contentType; }
|
||||
}
|
||||
|
||||
public override string MediaType
|
||||
{
|
||||
get { return mediaType; }
|
||||
}
|
||||
|
||||
public override MessageVersion MessageVersion
|
||||
{
|
||||
get { return MessageVersion.None; }
|
||||
}
|
||||
|
||||
public override bool IsContentTypeSupported(string contentType)
|
||||
{
|
||||
return innerReadMessageEncoder.IsContentTypeSupported(contentType);
|
||||
}
|
||||
|
||||
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
|
||||
{
|
||||
return innerReadMessageEncoder.ReadMessage(buffer, bufferManager, contentType);
|
||||
}
|
||||
|
||||
public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
|
||||
{
|
||||
return innerReadMessageEncoder.ReadMessage(stream, maxSizeOfHeaders, contentType);
|
||||
}
|
||||
|
||||
public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
|
||||
}
|
||||
if (bufferManager == null)
|
||||
{
|
||||
throw TraceUtility.ThrowHelperError(new ArgumentNullException("bufferManager"), message);
|
||||
}
|
||||
if (maxMessageSize < 0)
|
||||
{
|
||||
throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize,
|
||||
SR2.GetString(SR2.ValueMustBeNonNegative)), message);
|
||||
}
|
||||
if (messageOffset < 0 || messageOffset > maxMessageSize)
|
||||
{
|
||||
throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset,
|
||||
SR2.GetString(SR2.JsonValueMustBeInRange, 0, maxMessageSize)), message);
|
||||
}
|
||||
|
||||
ThrowIfMismatchedMessageVersion(message);
|
||||
message.Properties.Encoder = this;
|
||||
BufferedMessageWriter messageWriter = new WebScriptMetadataBufferedMessageWriter(this);
|
||||
ArraySegment<byte> messageData = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);
|
||||
if (MessageLogger.LogMessagesAtTransportLevel)
|
||||
{
|
||||
MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
|
||||
}
|
||||
if (System.ServiceModel.Diagnostics.Application.TD.MessageWrittenByEncoderIsEnabled() && messageData != null)
|
||||
{
|
||||
System.ServiceModel.Diagnostics.Application.TD.MessageWrittenByEncoder(EventTraceActivityHelper.TryExtractActivity(message), messageData.Count, this);
|
||||
}
|
||||
return messageData;
|
||||
}
|
||||
|
||||
public override void WriteMessage(Message message, Stream stream)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
|
||||
}
|
||||
if (stream == null)
|
||||
{
|
||||
throw TraceUtility.ThrowHelperError(new ArgumentNullException("stream"), message);
|
||||
}
|
||||
ThrowIfMismatchedMessageVersion(message);
|
||||
message.Properties.Encoder = this;
|
||||
XmlDictionaryWriter xmlWriter = CreateWriter(stream);
|
||||
xmlWriter.WriteStartDocument();
|
||||
message.WriteMessage(xmlWriter);
|
||||
xmlWriter.WriteEndDocument();
|
||||
xmlWriter.Flush();
|
||||
xmlWriter.Close();
|
||||
if (MessageLogger.LogMessagesAtTransportLevel)
|
||||
{
|
||||
MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
|
||||
}
|
||||
}
|
||||
|
||||
XmlDictionaryWriter CreateWriter(Stream stream)
|
||||
{
|
||||
XmlWriterSettings settings = new XmlWriterSettings();
|
||||
settings.OmitXmlDeclaration = true;
|
||||
settings.Encoding = UTF8EncodingWithoutByteOrderMark;
|
||||
XmlWriter writer = XmlWriter.Create(stream, settings);
|
||||
return XmlDictionaryWriter.CreateDictionaryWriter(writer);
|
||||
}
|
||||
|
||||
class WebScriptMetadataBufferedMessageWriter : BufferedMessageWriter
|
||||
{
|
||||
WebScriptMetadataMessageEncoder messageEncoder;
|
||||
|
||||
public WebScriptMetadataBufferedMessageWriter(WebScriptMetadataMessageEncoder messageEncoder)
|
||||
{
|
||||
this.messageEncoder = messageEncoder;
|
||||
}
|
||||
|
||||
protected override void OnWriteEndMessage(XmlDictionaryWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnWriteStartMessage(XmlDictionaryWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ReturnXmlWriter(XmlDictionaryWriter writer)
|
||||
{
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
protected override XmlDictionaryWriter TakeXmlWriter(Stream stream)
|
||||
{
|
||||
return messageEncoder.CreateWriter(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Channels
|
||||
{
|
||||
using System.ServiceModel;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
sealed class WebScriptMetadataMessageEncodingBindingElement : MessageEncodingBindingElement
|
||||
{
|
||||
XmlDictionaryReaderQuotas readerQuotas;
|
||||
|
||||
public WebScriptMetadataMessageEncodingBindingElement()
|
||||
{
|
||||
this.readerQuotas = new XmlDictionaryReaderQuotas();
|
||||
EncoderDefaults.ReaderQuotas.CopyTo(this.readerQuotas);
|
||||
}
|
||||
|
||||
WebScriptMetadataMessageEncodingBindingElement(WebScriptMetadataMessageEncodingBindingElement elementToBeCloned)
|
||||
: base(elementToBeCloned)
|
||||
{
|
||||
this.readerQuotas = new XmlDictionaryReaderQuotas();
|
||||
elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas);
|
||||
}
|
||||
|
||||
public override MessageVersion MessageVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return MessageVersion.None;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
|
||||
}
|
||||
if (value != MessageVersion.None)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR2.GetString(SR2.JsonOnlySupportsMessageVersionNone));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public XmlDictionaryReaderQuotas ReaderQuotas
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.readerQuotas;
|
||||
}
|
||||
}
|
||||
|
||||
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalBuildChannelFactory<TChannel>(context);
|
||||
}
|
||||
|
||||
public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalBuildChannelListener<TChannel>(context);
|
||||
}
|
||||
|
||||
public override bool CanBuildChannelFactory<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalCanBuildChannelFactory<TChannel>(context);
|
||||
}
|
||||
|
||||
public override bool CanBuildChannelListener<TChannel>(BindingContext context)
|
||||
{
|
||||
return InternalCanBuildChannelListener<TChannel>(context);
|
||||
}
|
||||
|
||||
public override BindingElement Clone()
|
||||
{
|
||||
return new WebScriptMetadataMessageEncodingBindingElement(this);
|
||||
}
|
||||
|
||||
public override MessageEncoderFactory CreateMessageEncoderFactory()
|
||||
{
|
||||
return new WebScriptMetadataMessageEncoderFactory(this.ReaderQuotas);
|
||||
}
|
||||
|
||||
public override T GetProperty<T>(BindingContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
|
||||
}
|
||||
if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
|
||||
{
|
||||
return (T)(object) this.readerQuotas;
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.GetProperty<T>(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user