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,76 @@
//
// AuthenticationService.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// (C) 2008 Mainsoft, Inc. http://www.mainsoft.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.Text;
using System.Web.Services;
using System.Web.Configuration;
using System.Web.Security;
namespace System.Web.Script.Services
{
sealed class AuthenticationService
{
public const string DefaultWebServicePath = "/Authentication_JSON_AppService.axd";
readonly ScriptingAuthenticationServiceSection _section;
public AuthenticationService () {
_section = (ScriptingAuthenticationServiceSection) WebConfigurationManager.GetSection ("system.web.extensions/scripting/webServices/authenticationService");
}
void EnsureEnabled() {
if (_section == null || !_section.Enabled)
throw new InvalidOperationException ("Authentication service is disabled.");
if (_section.RequireSSL && !HttpContext.Current.Request.IsSecureConnection)
throw new HttpException ("SSL is required for this operation.");
}
[WebMethod ()]
public bool Login (string userName, string password, bool createPersistentCookie) {
EnsureEnabled ();
if (!Membership.Provider.ValidateUser (userName, password))
return false;
FormsAuthentication.SetAuthCookie (userName, createPersistentCookie);
return true;
}
[WebMethod ()]
public void Logout () {
EnsureEnabled ();
FormsAuthentication.SignOut ();
}
}
}

View File

@ -0,0 +1,57 @@
2010-01-18 Marek Habersack <mhabersack@novell.com>
* LogicalTypeInfo.cs: partial revert of r146546. The 'd' wrapper
(and thus the JsonResult class) is needed after all. Fixes bug
#571365
2009-11-19 Marek Habersack <mhabersack@novell.com>
* LogicalTypeInfo.cs: removed the JsonResult class - it has no use
and it can break applications (e.g. Umbraco)
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* LogicalTypeInfo.cs, RestHandler.cs : add support for WCF proxy
generator. Make LogicalTypeInfo and LogicalMethodInfo abstract
and create sets of derivation for asmx and WCF. Large part of the
code still lives in abstract class, being reduced dependency on
ScriptServiceAttribute.
2009-08-15 Marek Habersack <mhabersack@novell.com>
* LogicalTypeInfo.cs: make sure JavaScriptSerializer instance used
here reads custom converters from web.config. Fixes bug #525589
2009-06-14 Robert Jordan <robertj@gmx.net>
* ScriptHandlerFactory.cs: handle precompiled web services.
2009-04-07 Gonzalo Paniagua Javier <gonzalo@novell.com>
* ClientProxyHandler.cs: set cacheability to public.
2009-04-03 Marek Habersack <mhabersack@novell.com>
* LogicalTypeInfo.cs: don't throw NREX when the passed type
doesn't have a parameterless constructor in
ShouldGenerateScript. Fixes bug #485435
2009-01-26 Marek Habersack <mhabersack@novell.com>
* ClientProxyHandler.cs: before generating the proxy check if the
service type is decorated with the [ScriptService] custom
attribute. Only such service types can be called from client
JavaScript.
2008-09-23 Marek Habersack <mhabersack@novell.com>
* LogicalTypeInfo.cs: do not use
LazyDictionary as enum serializer anymore.
* ProfileService.cs: do not use
LazyDictionary as ProfileService serializer anymore.
* RestHandler.cs: do not use
LazyDictionary as the Exception or NameValueCollection serializer
anymore.

View File

@ -0,0 +1,70 @@
//
// ScriptHandlerFactory.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
namespace System.Web.Script.Services
{
sealed class ClientProxyHandler : IHttpHandler
{
readonly LogicalTypeInfo _logicalTypeInfo;
readonly Type _type;
public ClientProxyHandler (Type type, string filePath)
{
_type = type;
_logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (type, filePath);
}
#region IHttpHandler Members
public bool IsReusable {
get { return false; }
}
public void ProcessRequest (HttpContext context)
{
HttpResponse response = context.Response;
object[] attributes = _type.GetCustomAttributes (typeof (ScriptServiceAttribute), true);
if (attributes.Length == 0) {
response.ContentType = "text/html";
throw new InvalidOperationException ("Only Web services with a [ScriptService] attribute on the class definition can be called from script.");
}
response.ContentType = "application/x-javascript";
response.Cache.SetExpires (DateTime.UtcNow.AddYears (1));
response.Cache.SetValidUntilExpires (true);
response.Cache.SetCacheability (HttpCacheability.Public);
response.Output.Write (_logicalTypeInfo.Proxy);
}
#endregion
}
}

View File

@ -0,0 +1,63 @@
//
// GenerateScriptTypeAttribute.cs
//
// Author:
// Igor Zelmanovich <igorz@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
namespace System.Web.Script.Services
{
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Interface, AllowMultiple = true)]
public sealed class GenerateScriptTypeAttribute : Attribute
{
readonly Type _type;
string _typeId;
public GenerateScriptTypeAttribute (Type type) {
if (type == null)
throw new ArgumentNullException ("type");
_type = type;
}
public string ScriptTypeId {
get {
return _typeId == null ? String.Empty : _typeId;
}
set {
_typeId = value;
}
}
public Type Type {
get {
return _type;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,156 @@
//
// ScriptHandlerFactory.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
using System.Web.Services;
using System.Configuration;
using System.Web.Configuration;
using System.Web.Script.Serialization;
using System.Web.Profile;
namespace System.Web.Script.Services
{
sealed class ProfileService
{
public const string DefaultWebServicePath = "/Profile_JSON_AppService.axd";
readonly ScriptingProfileServiceSection _section;
public ProfileService () {
_section = (ScriptingProfileServiceSection) WebConfigurationManager.GetSection ("system.web.extensions/scripting/webServices/profileService");
}
ScriptingProfileServiceSection ScriptingProfileServiceSection {
get {
if (_section == null || !_section.Enabled)
throw new InvalidOperationException ("Profile service is disabled.");
return _section;
}
}
public IDictionary <string, object> GetProfileDictionary (string[] properties)
{
var ret = new Dictionary <string, object> ();
int len = properties != null ? properties.Length : 0;
if (len <= 0)
return ret;
ProfileBase profile = HttpContext.Current.Profile;
string name;
int dot;
object value;
for (int i = 0; i < len; i++) {
name = properties [i];
dot = name.IndexOf ('.');
value = (dot > 0) ? profile.GetProfileGroup (name.Substring (0, dot)).GetPropertyValue (name.Substring (dot + 1)) : profile.GetPropertyValue (name);
ret.Add (name, value);
}
return ret;
}
[WebMethod()]
public IDictionary<string, object> GetAllPropertiesForCurrentUser (bool authenticatedUserOnly) {
return GetProfileDictionary (ScriptingProfileServiceSection.ReadAccessProperties);
}
[WebMethod ()]
public IDictionary<string, object> GetPropertiesForCurrentUser (string [] properties, bool authenticatedUserOnly) {
if (properties == null)
return GetAllPropertiesForCurrentUser (authenticatedUserOnly);
string [] raProps = ScriptingProfileServiceSection.ReadAccessPropertiesNoCopy;
List<string> list = null;
for (int i = 0; i < properties.Length; i++) {
string prop = properties [i];
if (prop == null)
throw new ArgumentNullException ("properties[" + i + "]");
if (IsPropertyConfigured(raProps, prop)) {
if (list != null)
list.Add(prop);
}
else if (list == null) {
list = new List<string> (properties.Length - 1);
for (int k = 0; k < i; k++)
list.Add (properties [k]);
}
}
return GetProfileDictionary (list != null ? list.ToArray () : properties);
}
[WebMethod ()]
public string [] SetPropertiesForCurrentUser (Dictionary<string, object> values, bool authenticatedUserOnly) {
if (values == null)
return new string [] { };
string [] waProps = ScriptingProfileServiceSection.WriteAccessPropertiesNoCopy;
List<string> list = new List<string> ();
ProfileBase profile = HttpContext.Current.Profile;
foreach (KeyValuePair<string, object> pair in values) {
try {
string name = pair.Key;
if (!IsPropertyConfigured (waProps, name))
continue;
int dot = name.IndexOf ('.');
if (dot > 0)
profile.GetProfileGroup (name.Substring (0, dot))
.SetPropertyValue (name.Substring (dot + 1), pair.Value);
else
profile.SetPropertyValue (name, pair.Value);
}
catch {
list.Add (pair.Key);
}
}
return list.ToArray ();
}
static bool IsPropertyConfigured (string [] configuredProperties, string propertyToCheck) {
if (configuredProperties == null)
return false;
bool found = false;
for (int i = 0; !found && i < configuredProperties.Length; i++)
found = configuredProperties [i].Equals (propertyToCheck, StringComparison.OrdinalIgnoreCase);
return found;
}
}
}

View File

@ -0,0 +1,42 @@
//
// ProxyGenerator.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// (C) 2008 Mainsoft, Inc. http://www.mainsoft.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.Text;
namespace System.Web.Script.Services
{
public static class ProxyGenerator
{
public static string GetClientProxyScript (Type type, string path, bool debug) {
return LogicalTypeInfo.GetLogicalTypeInfo (type, path).Proxy;
}
}
}

View File

@ -0,0 +1,41 @@
//
// ResponseFormat.cs
//
// Author:
// Igor Zelmanovich <igorz@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
namespace System.Web.Script.Services
{
public enum ResponseFormat
{
Json = 0,
Xml = 1,
}
}

View File

@ -0,0 +1,158 @@
//
// RestHandler.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
using System.Web.Script.Serialization;
using System.Collections.Specialized;
using System.IO;
using System.Web.SessionState;
using System.Reflection;
namespace System.Web.Script.Services
{
sealed class RestHandler : IHttpHandler
{
#region SessionWrappers
class SessionWrapperHandler : IHttpHandler, IRequiresSessionState
{
readonly IHttpHandler _handler;
public SessionWrapperHandler (IHttpHandler handler) {
_handler = handler;
}
public bool IsReusable {
get { return _handler.IsReusable; }
}
public void ProcessRequest (HttpContext context) {
_handler.ProcessRequest (context);
}
}
sealed class ReadOnlySessionWrapperHandler : SessionWrapperHandler, IReadOnlySessionState
{
public ReadOnlySessionWrapperHandler (IHttpHandler handler) : base (handler) { }
}
#endregion
#region ExceptionSerializer
sealed class ExceptionSerializer
{
readonly Exception _e;
public ExceptionSerializer (Exception e) {
_e = e;
}
public string Message {
get { return _e.Message; }
}
public string StackTrace {
get { return _e.StackTrace; }
}
public string ExceptionType {
get { return _e.GetType ().FullName; }
}
}
#endregion
readonly LogicalTypeInfo.LogicalMethodInfo _logicalMethodInfo;
private RestHandler (HttpContext context, Type type, string filePath) {
LogicalTypeInfo logicalTypeInfo = LogicalTypeInfo.GetLogicalTypeInfo (type, filePath);
HttpRequest request = context.Request;
string methodName = request.PathInfo.Substring (1);
if (logicalTypeInfo == null || String.IsNullOrEmpty(methodName))
ThrowInvalidOperationException (methodName);
_logicalMethodInfo = logicalTypeInfo [methodName];
if (_logicalMethodInfo == null)
ThrowInvalidOperationException (methodName);
}
static void ThrowInvalidOperationException (string pathInfo) {
throw new InvalidOperationException (
string.Format ("Request format is unrecognized unexpectedly ending in '{0}'.", pathInfo));
}
static readonly Type IRequiresSessionStateType = typeof (IRequiresSessionState);
static readonly Type IReadOnlySessionStateType = typeof (IReadOnlySessionState);
public static IHttpHandler GetHandler (HttpContext context, Type type, string filePath) {
RestHandler handler = new RestHandler (context, type, filePath);
LogicalTypeInfo.LogicalMethodInfo mi = handler._logicalMethodInfo;
if (mi.MethodInfo.IsStatic) {
if (IRequiresSessionStateType.IsAssignableFrom (type))
return IReadOnlySessionStateType.IsAssignableFrom (type) ?
new ReadOnlySessionWrapperHandler (handler) : new SessionWrapperHandler (handler);
}
else
if (mi.EnableSession)
return new SessionWrapperHandler (handler);
return handler;
}
#region IHttpHandler Members
public bool IsReusable {
get { return false; }
}
public void ProcessRequest (HttpContext context) {
HttpRequest request = context.Request;
HttpResponse response = context.Response;
response.ContentType =
_logicalMethodInfo.ResponseFormat == ResponseFormat.Json ?
"application/json" : "text/xml";
response.Cache.SetCacheability (HttpCacheability.Private);
response.Cache.SetMaxAge (TimeSpan.Zero);
try {
_logicalMethodInfo.Invoke (request, response);
}
catch (TargetInvocationException e) {
response.AddHeader ("jsonerror", "true");
response.ContentType = "application/json";
response.StatusCode = 500;
JavaScriptSerializer.DefaultSerializer.Serialize (new ExceptionSerializer (e.GetBaseException ()), response.Output);
response.End ();
}
}
#endregion
}
}

View File

@ -0,0 +1,79 @@
//
// ScriptHandlerFactory.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
using System.Web.Compilation;
using System.Web.Services.Protocols;
using System.Web.UI;
namespace System.Web.Script.Services
{
sealed class ScriptHandlerFactory : IHttpHandlerFactory
{
readonly WebServiceHandlerFactory _wsFactory;
public ScriptHandlerFactory () {
_wsFactory = new WebServiceHandlerFactory ();
}
#region IHttpHandlerFactory Members
public IHttpHandler GetHandler (HttpContext context, string requestType, string url, string pathTranslated) {
HttpRequest request = context.Request;
string contentType = request.ContentType;
if (!String.IsNullOrEmpty (contentType) && contentType.StartsWith ("application/json", StringComparison.OrdinalIgnoreCase)) {
Type handlerType = null;
if (url.EndsWith (ProfileService.DefaultWebServicePath, StringComparison.Ordinal))
handlerType = typeof (ProfileService);
else
if (url.EndsWith (AuthenticationService.DefaultWebServicePath, StringComparison.Ordinal))
handlerType = typeof(AuthenticationService);
else {
#if !TARGET_JVM
handlerType = BuildManager.GetCompiledType (url);
#endif
if (handlerType == null)
handlerType = WebServiceParser.GetCompiledType (url, context);
}
return RestHandler.GetHandler (context, handlerType, url);
}
if (request.PathInfo.StartsWith ("/js", StringComparison.OrdinalIgnoreCase))
return new ClientProxyHandler (WebServiceParser.GetCompiledType (url, context), url);
return _wsFactory.GetHandler (context, requestType, url, pathTranslated);
}
public void ReleaseHandler (IHttpHandler handler) {
}
#endregion
}
}

View File

@ -0,0 +1,59 @@
//
// ScriptMethodAttribute.cs
//
// Author:
// Igor Zelmanovich <igorz@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
namespace System.Web.Script.Services
{
[AttributeUsage (AttributeTargets.Method)]
public sealed class ScriptMethodAttribute : Attribute
{
ResponseFormat _responseFormat = ResponseFormat.Json;
bool _useHttpGet;
bool _xmlSerializeString;
internal static readonly ScriptMethodAttribute Default = new ScriptMethodAttribute ();
public ResponseFormat ResponseFormat {
get { return _responseFormat; }
set { _responseFormat = value; }
}
public bool UseHttpGet {
get { return _useHttpGet; }
set { _useHttpGet = value; }
}
public bool XmlSerializeString {
get { return _xmlSerializeString; }
set { _xmlSerializeString = value; }
}
}
}

View File

@ -0,0 +1,40 @@
//
// ScriptServiceAttribute.cs
//
// Author:
// Igor Zelmanovich <igorz@mainsoft.com>
//
// (C) 2007 Mainsoft, Inc. http://www.mainsoft.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.Text;
namespace System.Web.Script.Services
{
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Interface)]
public sealed class ScriptServiceAttribute : Attribute
{
}
}