Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,168 @@
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : do not depend on WebOperationContext.
add support for Raw format request.
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : add support for Raw format.
2010-07-06 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : add NET_2_1 profile build.
2010-05-24 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverter.cs : objects are regarded serializable as
long as they are public here, with some exceptions (not implemented).
2010-03-16 Jb Evain <jbevain@novell.com>
* WebMessageFormatter.cs: use MOONLIGHT symbol to
disambiguate MonoTouch and Moonlight code.
2009-10-23 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverter.cs
QueryStringConverter.cs
WebMessageFormatter.cs : add experimental monotouch build.
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncoder.cs : use alwaysEmitTypeInformation to output
object __type.
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverter.cs : add custom body name support (used.
for AJAX). Handle string value (in very LAMESPEC way).
* WebMessageFormatter.cs : add custom body name support.
Slightly changed reply serialization.
Convert deserialized values using QueryStringConverter.
2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : revert and fix wrapper name change. XML
and JSON have different serialization.
2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : also fix wrapped message deserialization.
It should expect FooResponse (body WrapperName), not FooResult
(ReturnValue part Name).
2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : when they serialize Wrapped message, it
first writes "root" and then the wrapper element.
2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : JSON writer does not support namespace.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : it was not returning value with correct
wrapper name/namespace. Fix interop with .NET client.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : Made the same prohibition for dispatch
formatters too. Support WebMessageBodyStyle on dispatcher side too.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : override some serialization methods as
prohibited.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpDispatchOperationSelector.cs : use common extension method.
* WebMessageFormatter.cs : support WebMessageBodyStyle(.Wrapped*).
Cache serializers.
2009-07-28 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : apply OutgoingRequest if available.
2008-04-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : now that ReadObject() verifies
by default, it broke deserialization. Fixed it.
2008-02-18 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverter.cs : implemented.
2008-02-17 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : implement WebOperationContext support.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpDispatchOperationSelector.cs : some code cleanup.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : fixed content-type typo.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : implemented DeserializeReply().
It was wrong to have one MessageDescription in a formatter, as
they are different between serialization and deserialization.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : oops oops. not "encoding" but "charset".
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : hack SerializeReply().
Add WebBodyFormat property
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : implement DeserializeRequest().
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : attach a HttpRequestMessageProperty when
creating a request Message.
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpDispatchOperationSelector.cs : implemented large part of it.
* WebMessageFormatter.cs : moved BuildUriTemplate to WebAttributeInfo.
2008-02-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : pass WebHttpBehavior too.
2008-02-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : pass QueryStringConverter which is used to
convert parameter objects to the components of the request URI.
2008-02-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : new message formatter that is created
from WebHttpBehavior and handles [WebGet] or [WebInvoke]. Not done.
2008-02-13 Atsushi Enomoto <atsushi@ximian.com>
* QueryStringConverter.cs : I could just check null parameter.
2008-02-13 Atsushi Enomoto <atsushi@ximian.com>
* QueryStringConverter.cs: CanConvert() supports cpl more types.
Implemented ConvertStringToValue() and ConvertValueToString().
2008-02-12 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpDispatchOperationSelector.cs : stubbed members.
2008-02-07 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverter.cs, QueryStringConverter.cs,
WebHttpDispatchOperationSelector.cs : mostly stubs.

View File

@ -0,0 +1,224 @@
//
// JsonQueryStringConverter.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
// Copyright 2014 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization.Json;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
namespace System.ServiceModel.Dispatcher
{
public class JsonQueryStringConverter : QueryStringConverter
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer (typeof (object));
internal string CustomWrapperName { get; set; }
public override bool CanConvert (Type type)
{
// almost copy from QueryStringConverter, except that DBNull and XmlQualifiedName are supported
switch (Type.GetTypeCode (type)) {
//case TypeCode.DBNull:
case TypeCode.Empty:
return false;
case TypeCode.Object:
if (type == typeof (TimeSpan))
return true;
if (type == typeof (DateTimeOffset))
return true;
if (type == typeof (Guid))
return true;
if (type == typeof (XmlQualifiedName))
return true;
if (type == typeof (object))
return true;
// if (type.GetCustomAttributes (typeof (TypeConverterAttribute), true).Length > 0)
// return true;
// FIXME: it should return false for things like List<OfPrivateType>.
return type.IsPublic || type.IsNestedPublic;
default:
return true;
}
}
public override object ConvertStringToValue (string parameter, Type parameterType)
{
if (parameterType == null)
throw new ArgumentNullException ("parameterType");
if (!CanConvert (parameterType))
throw new NotSupportedException (String.Format ("Conversion from the argument parameterType '{0}' is not supported", parameterType));
// In general .NET JSON parser is sloppy. It accepts
// such a string that is actually invalid in terms of
// the target type in JSON context.
switch (Type.GetTypeCode (parameterType)) {
case TypeCode.String:
// LAMESPEC LAMESPEC LAMESPEC: we cannot give "foo" as the string value input (even if they are escaped as %22!)
if (parameter == null)
return null;
if (parameter.Length > 1 && parameter [0] == '"' && parameter [parameter.Length - 1] == '"')
return parameter.Substring (1, parameter.Length - 2);
else if (parameter [0] != '"')
return parameter;
break;
case TypeCode.Char:
return parameter != null ? Char.Parse (parameter): default (char);
case TypeCode.SByte:
return parameter != null ? SByte.Parse (parameter, CultureInfo.InvariantCulture): default (sbyte);
case TypeCode.Byte:
return parameter != null ? Byte.Parse (parameter, CultureInfo.InvariantCulture): default (byte);
case TypeCode.Int16:
return parameter != null ? Int16.Parse (parameter, CultureInfo.InvariantCulture): default (short);
case TypeCode.Int32:
return parameter != null ? Int32.Parse (parameter, CultureInfo.InvariantCulture): default (int);
case TypeCode.Int64:
return parameter != null ? Int64.Parse (parameter, CultureInfo.InvariantCulture): default (long);
case TypeCode.UInt16:
return parameter != null ? UInt16.Parse (parameter, CultureInfo.InvariantCulture): default (ushort);
case TypeCode.UInt32:
return parameter != null ? UInt32.Parse (parameter, CultureInfo.InvariantCulture): default (uint);
case TypeCode.UInt64:
return parameter != null ? UInt64.Parse (parameter, CultureInfo.InvariantCulture): default (ulong);
case TypeCode.DateTime:
return parameter != null ? DateTime.Parse (parameter, CultureInfo.InvariantCulture): default (DateTime);
case TypeCode.Boolean:
return parameter != null ? Boolean.Parse (parameter): default (bool);
case TypeCode.Single:
return parameter != null ? Single.Parse (parameter, CultureInfo.InvariantCulture): default (float);
case TypeCode.Double:
return parameter != null ? Double.Parse (parameter, CultureInfo.InvariantCulture): default (double);
case TypeCode.Decimal:
return parameter != null ? Decimal.Parse (parameter, CultureInfo.InvariantCulture): default (decimal);
}
if (parameter == null)
return null;
DataContractJsonSerializer serializer =
new DataContractJsonSerializer (parameterType);
// hmm, it costs so silly though.
return serializer.ReadObject (new MemoryStream (Encoding.UTF8.GetBytes (parameter)));
}
bool IsKnownType (Type t)
{
switch (Type.GetTypeCode (t)) {
case TypeCode.Object:
if (t == typeof (Guid) ||
t == typeof (DBNull) ||
t == typeof (DateTimeOffset) ||
t == typeof (TimeSpan) ||
t == typeof (XmlQualifiedName))
return true;
return false;
default:
return true;
}
}
public override string ConvertValueToString (object parameter, Type parameterType)
{
if (parameterType == null)
throw new ArgumentNullException ("parameterType");
if (!CanConvert (parameterType))
throw new NotSupportedException (String.Format ("Conversion from the argument parameterType '{0}' is not supported", parameterType));
if (parameter == null)
return null;
if (parameter is DBNull)
return "{}";
parameterType = ToActualType (parameterType);
if (parameter is IConvertible)
parameter = ((IConvertible) parameter).ToType (parameterType, CultureInfo.InvariantCulture);
switch (Type.GetTypeCode (parameterType)) {
case TypeCode.String:
string s = parameter is IFormattable ?
((IFormattable) parameter).ToString (null, CultureInfo.InvariantCulture) :
parameter.ToString ();
StringBuilder sb = new StringBuilder (s);
sb.Replace ("\"", "\\\"");
sb.Insert (0, "\"");
sb.Append ('\"');
return sb.ToString ();
default:
if (parameterType == typeof (XmlQualifiedName)) {
var qname = (XmlQualifiedName) parameter;
return String.Concat ("\"", qname.Name, ":", qname.Namespace, "\"");
}
var f = (parameter as IFormattable);
return (f == null) ? parameter.ToString () : f.ToString (null, CultureInfo.InvariantCulture);
}
}
Type ToActualType (Type t)
{
switch (Type.GetTypeCode (t)) {
case TypeCode.DBNull: // though DBNull.Value input is converted to "{}". This result is used for String input.
case TypeCode.Char:
case TypeCode.String:
return typeof (string);
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
// return typeof (long);
return typeof (decimal);
case TypeCode.Byte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
// return typeof (ulong);
return typeof (decimal);
case TypeCode.DateTime:
case TypeCode.Boolean:
return t;
case TypeCode.Single:
case TypeCode.Double:
// return typeof (double);
return typeof (decimal);
case TypeCode.Decimal:
return typeof (decimal);
default:
return t;
}
}
}
}

View File

@ -0,0 +1,138 @@
//
// QueryStringConverter.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.ComponentModel;
using System.Globalization;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace System.ServiceModel.Dispatcher
{
public class QueryStringConverter
{
// "Service Operation Parameters and URLs"
// http://msdn2.microsoft.com/en-us/library/bb412172.aspx
public virtual bool CanConvert (Type type)
{
switch (Type.GetTypeCode (type)) {
case TypeCode.DBNull:
case TypeCode.Empty:
return false;
case TypeCode.Object:
if (type == typeof (TimeSpan))
return true;
if (type == typeof (DateTimeOffset))
return true;
if (type == typeof (Guid))
return true;
if (type == typeof (object))
return true;
// if (type.GetCustomAttributes (typeof (TypeConverterAttribute), true).Length > 0)
// return true;
return false;
default:
return true;
}
}
public virtual object ConvertStringToValue (string parameter, Type parameterType)
{
if (parameterType == null)
throw new ArgumentNullException ("parameterType");
if (!CanConvert (parameterType))
throw new NotSupportedException (String.Format ("Conversion from the argument parameterType '{0}' is not supported", parameterType));
if (parameterType.IsEnum)
return Enum.Parse(parameterType, parameter, true);
switch (Type.GetTypeCode (parameterType)) {
case TypeCode.String:
return parameter;
case TypeCode.Char:
return parameter != null ? Char.Parse (parameter) : default (char);
case TypeCode.SByte:
return parameter != null ? SByte.Parse (parameter, CultureInfo.InvariantCulture): default (sbyte);
case TypeCode.Byte:
return parameter != null ? Byte.Parse (parameter, CultureInfo.InvariantCulture): default (byte);
case TypeCode.Int16:
return parameter != null ? Int16.Parse (parameter, CultureInfo.InvariantCulture): default (short);
case TypeCode.Int32:
return parameter != null ? Int32.Parse (parameter, CultureInfo.InvariantCulture): default (int);
case TypeCode.Int64:
return parameter != null ? Int64.Parse (parameter, CultureInfo.InvariantCulture): default (long);
case TypeCode.UInt16:
return parameter != null ? UInt16.Parse (parameter, CultureInfo.InvariantCulture): default (ushort);
case TypeCode.UInt32:
return parameter != null ? UInt32.Parse (parameter, CultureInfo.InvariantCulture): default (uint);
case TypeCode.UInt64:
return parameter != null ? UInt64.Parse (parameter, CultureInfo.InvariantCulture): default (ulong);
case TypeCode.DateTime:
return parameter != null ? DateTime.Parse (parameter, CultureInfo.InvariantCulture): default (DateTime);
case TypeCode.Boolean:
return parameter != null ? Boolean.Parse (parameter): default (bool);
case TypeCode.Single:
return parameter != null ? Single.Parse (parameter, CultureInfo.InvariantCulture): default (float);
case TypeCode.Double:
return parameter != null ? Double.Parse (parameter, CultureInfo.InvariantCulture): default (double);
case TypeCode.Decimal:
return parameter != null ? Decimal.Parse (parameter, CultureInfo.InvariantCulture): default (decimal);
case TypeCode.Object:
if (parameterType == typeof (TimeSpan))
return TimeSpan.Parse (parameter);
if (parameterType == typeof (DateTimeOffset))
return DateTimeOffset.Parse (parameter, CultureInfo.InvariantCulture);
if (parameterType == typeof (Guid))
return new Guid (parameter);
break;
}
throw new NotSupportedException (String.Format ("Cannot convert parameter string '{0}' to parameter type '{1}'", parameter, parameterType));
}
public virtual string ConvertValueToString (object parameter, Type parameterType)
{
if (parameterType == null)
throw new ArgumentNullException ("parameterType");
if (parameterType.IsValueType && parameter == null)
throw new ArgumentNullException ("parameter");
if (parameter == null)
return null;
if (parameter.GetType () != parameterType)
throw new InvalidCastException (String.Format ("This QueryStringConverter does not support cast from {0} to {1}", parameter.GetType (), parameterType));
if (!CanConvert (parameterType))
throw new NotSupportedException (String.Format ("Conversion from the argument parameterType '{0}' is not supported", parameterType));
if (parameter is IFormattable)
((IFormattable) parameter).ToString (null, CultureInfo.InvariantCulture);
return parameter.ToString ();
}
}
}

View File

@ -0,0 +1,121 @@
//
// WebHttpDispatchOperationSelector.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using TemplateTablePair = System.Collections.Generic.KeyValuePair<System.UriTemplate, object>;
namespace System.ServiceModel.Dispatcher
{
public class WebHttpDispatchOperationSelector : IDispatchOperationSelector
{
public const string HttpOperationSelectorUriMatchedPropertyName = "UriMatched";
Dictionary<string,UriTemplateTable> tables = new Dictionary<string,UriTemplateTable> ();
protected WebHttpDispatchOperationSelector ()
{
}
public WebHttpDispatchOperationSelector (ServiceEndpoint endpoint)
{
if (endpoint == null)
throw new ArgumentNullException ("endpoint");
if (endpoint.Address == null)
throw new InvalidOperationException ("EndpointAddress must be set in the argument ServiceEndpoint");
foreach (OperationDescription od in endpoint.Contract.Operations) {
WebAttributeInfo info = od.GetWebAttributeInfo ();
if (info != null) {
UriTemplateTable table;
if (!tables.TryGetValue (info.Method, out table)) {
table = new UriTemplateTable (endpoint.Address.Uri);
tables.Add (info.Method, table);
}
table.KeyValuePairs.Add (new TemplateTablePair (info.BuildUriTemplate (od, null), od));
}
}
}
public string SelectOperation (ref Message message)
{
// FIXME: uriMatched should be used to differentiate 404 and 405 (method not allowed)
bool uriMatched;
return SelectOperation (ref message, out uriMatched);
}
protected virtual string SelectOperation (ref Message message, out bool uriMatched)
{
if (message == null)
throw new ArgumentNullException ("message");
if (message.Properties.ContainsKey (UriMatchedProperty.Name))
throw new ArgumentException (String.Format ("There is already a message property for template-matched URI '{0}'", UriMatchedProperty.Name));
uriMatched = false;
var hp = (HttpRequestMessageProperty) message.Properties [HttpRequestMessageProperty.Name];
OperationDescription od = null;
Message dummy = message; // since lambda expression prohibits ref variable...
Uri to = message.Headers.To;
// First, UriTemplateTable with corresponding HTTP method is tested. Then other tables can be tested for match.
UriTemplateTable table = null;
if (hp != null && hp.Method != null)
tables.TryGetValue (hp.Method, out table);
// FIXME: looks like To header does not matter on .NET. (But how to match then? I have no idea)
UriTemplateMatch match = to == null || table == null ? null : table.MatchSingle (to);
if (to != null && match == null) {
foreach (var tab in tables.Values)
if ((match = tab.MatchSingle (to)) != null) {
table = tab;
break;
}
}
if (match != null) {
uriMatched = true;
foreach (TemplateTablePair p in table.KeyValuePairs)
if (p.Key == match.Template)
od = p.Value as OperationDescription;
}
if (od != null)
message.Properties.Add (UriMatchedProperty.Name, new UriMatchedProperty ());
return uriMatched && od != null ? od.Name : String.Empty;
}
internal class UriMatchedProperty
{
public static string Name = "UriMatched"; // this is what .NET uses for MessageProperty that represents a matched URI.
}
}
}