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,66 @@
//
// System.Web.Services.Protocols.AnyReturnReader.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.IO;
using System.Net;
using System.Web.Services;
namespace System.Web.Services.Protocols {
public class AnyReturnReader : MimeReturnReader {
#region Constructors
public AnyReturnReader ()
{
}
#endregion // Constructors
#region Methods
public override object GetInitializer (LogicalMethodInfo methodInfo)
{
return null;
}
public override void Initialize (object o)
{
// do nothing
}
// returns the input HTTP response stream.
public override object Read (WebResponse response, Stream responseStream)
{
return responseStream;
}
#endregion // Methods
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,231 @@
//
// System.Web.Services.Protocols.Fault.cs
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) 2004 Novell, Inc.
//
//
// 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.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Text;
using System.Collections;
using System.Globalization;
namespace System.Web.Services.Protocols
{
internal class Fault
{
static XmlSerializer serializer;
static Fault ()
{
serializer = new FaultSerializer ();
}
public Fault () {}
public Fault (SoapException ex)
{
faultcode = ex.Code;
faultstring = ex.Message;
faultactor = ex.Actor;
detail = ex.Detail;
}
[XmlElement (Namespace="")]
public XmlQualifiedName faultcode;
[XmlElement (Namespace="")]
public string faultstring;
[XmlElement (Namespace="")]
public string faultactor;
[SoapIgnore]
public XmlNode detail;
public static XmlSerializer Serializer
{
get { return serializer; }
}
}
internal class FaultSerializer : XmlSerializer
{
protected override void Serialize (object o, XmlSerializationWriter writer)
{
FaultWriter xsWriter = writer as FaultWriter;
xsWriter.WriteRoot_Fault (o);
}
protected override object Deserialize (XmlSerializationReader reader)
{
FaultReader xsReader = reader as FaultReader;
return xsReader.ReadRoot_Fault ();
}
protected override XmlSerializationWriter CreateWriter ()
{
return new FaultWriter ();
}
protected override XmlSerializationReader CreateReader ()
{
return new FaultReader ();
}
}
internal class FaultReader : XmlSerializationReader
{
public object ReadRoot_Fault ()
{
Reader.MoveToContent();
if (Reader.LocalName != "Fault" || Reader.NamespaceURI != WebServiceHelper.SoapEnvelopeNamespace)
throw CreateUnknownNodeException();
return ReadObject_Fault (true, true);
}
public System.Web.Services.Protocols.Fault ReadObject_Fault (bool isNullable, bool checkType)
{
System.Web.Services.Protocols.Fault ob = null;
if (isNullable && ReadNull()) return null;
if (checkType)
{
System.Xml.XmlQualifiedName t = GetXsiType();
if (t != null)
{
if (t.Name != "Fault" || t.Namespace != WebServiceHelper.SoapEnvelopeNamespace)
throw CreateUnknownTypeException(t);
}
}
ob = new System.Web.Services.Protocols.Fault ();
Reader.MoveToElement();
while (Reader.MoveToNextAttribute())
{
if (IsXmlnsAttribute (Reader.Name)) {
}
else {
UnknownNode (ob);
}
}
Reader.MoveToElement();
if (Reader.IsEmptyElement) {
Reader.Skip ();
return ob;
}
Reader.ReadStartElement();
Reader.MoveToContent();
bool b0=false, b1=false, b2=false, b3=false;
while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
if (Reader.NamespaceURI == string.Empty || Reader.NamespaceURI == WebServiceHelper.SoapEnvelopeNamespace) {
if (Reader.LocalName == "faultcode" && !b0) {
b0 = true;
ob.@faultcode = ReadElementQualifiedName ();
} else if (Reader.LocalName == "faultstring" && !b1) {
b1 = true;
ob.@faultstring = Reader.ReadElementString ();
} else if (Reader.LocalName == "detail" && !b3) {
b3 = true;
ob.@detail = ReadXmlNode (false);
} else if (Reader.LocalName == "faultactor" && !b2) {
b2 = true;
ob.@faultactor = Reader.ReadElementString ();
} else {
UnknownNode (ob);
}
} else {
UnknownNode (ob);
}
} else
UnknownNode(ob);
Reader.MoveToContent();
}
ReadEndElement();
return ob;
}
protected override void InitCallbacks ()
{
}
protected override void InitIDs ()
{
}
}
internal class FaultWriter : XmlSerializationWriter
{
public void WriteRoot_Fault (object o)
{
WriteStartDocument ();
System.Web.Services.Protocols.Fault ob = (System.Web.Services.Protocols.Fault) o;
TopLevelElement ();
WriteObject_Fault (ob, "Fault", WebServiceHelper.SoapEnvelopeNamespace, true, false, true);
}
void WriteObject_Fault (System.Web.Services.Protocols.Fault ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
{
if (ob == null)
{
if (isNullable)
WriteNullTagLiteral(element, namesp);
return;
}
if (writeWrappingElem) {
WriteStartElement (element, namesp, ob);
}
if (needType) WriteXsiType ("Fault", WebServiceHelper.SoapEnvelopeNamespace);
WriteElementQualifiedName ("faultcode", "", ob.@faultcode);
WriteElementString ("faultstring", "", ob.@faultstring);
WriteElementString ("faultactor", "", ob.@faultactor);
WriteElementLiteral (ob.@detail, "detail", "", false, false);
if (writeWrappingElem) WriteEndElement (ob);
}
protected override void InitCallbacks ()
{
}
}
}

View File

@@ -0,0 +1,169 @@
//
// Fault12.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc.
//
//
// 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.
//
//
// This file is used to generate Fault12Serializer.cs with fault-12.genxs.
// To generate the file, do:
// - replace _internal_ class in this file to _public_ class
// - optionally you might have to remove Fault12Serializer.cs from
// System.Web.Services.dll.sources.
// - Build System.Web.Services.dll with make PROFILE=net_2_0.
// - run genxs.exe with 2.0 libraries (the easiest way would be
// to build genxs under 2.0 profile i.e. make PROFILE=net_2_0)
// - Edit Fault12Serializer.cs to rename "FaultSerializer" to
// "Fault12Serializer" as the name is a duplicate, and
// wrap the entire code with #if NET_2_0.
// - revert _public_ class in this file to _internal_ class back.
//
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Text;
using System.Collections;
using System.Globalization;
namespace System.Web.Services.Protocols
{
[XmlRoot ("Fault", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
[XmlType ("Fault", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
internal class Soap12Fault
{
// dummy constructor to not be rejected by genxs.
public Soap12Fault ()
{
}
public static XmlSerializer Serializer =
#if NET_2_0
new Fault12Serializer ();
#else
null;
#endif
#if NET_2_0
public Soap12Fault (SoapException ex)
{
Code = new Soap12FaultCode ();
Code.Value = ex.Code;
if (ex.SubCode != null)
Code.Subcode = CreateFaultCode (ex.SubCode);
Node = ex.Node;
Role = ex.Role;
Reason = new Soap12FaultReason ();
Soap12FaultReasonText text =
new Soap12FaultReasonText ();
text.XmlLang = ex.Lang;
text.Value = ex.Message;
Reason.Texts = new Soap12FaultReasonText [] {text};
if (ex.Detail != null) {
Detail = new Soap12FaultDetail ();
if (ex.Detail.NodeType == XmlNodeType.Attribute)
Detail.Attributes = new XmlAttribute [] {
(XmlAttribute) ex.Detail};
else if (ex.Detail.NodeType == XmlNodeType.Element)
Detail.Children = new XmlElement [] {
(XmlElement) ex.Detail};
else
Detail.Text = ex.Detail.Value;
}
}
static Soap12FaultCode CreateFaultCode (SoapFaultSubCode code)
{
if (code == null)
throw new ArgumentNullException ("code");
Soap12FaultCode ret = new Soap12FaultCode ();
ret.Value = code.Code;
if (code.SubCode != null)
ret.Subcode = CreateFaultCode (code.SubCode);
return ret;
}
public static SoapFaultSubCode GetSoapFaultSubCode (Soap12FaultCode src)
{
return (src == null) ? null :
new SoapFaultSubCode (src.Value, GetSoapFaultSubCode (src.Subcode));
}
#endif
public Soap12FaultCode Code;
public Soap12FaultReason Reason;
[XmlElement (DataType = "anyURI")]
public string Node;
[XmlElement (DataType = "anyURI")]
public string Role;
public Soap12FaultDetail Detail;
}
[XmlType ("Code", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
internal class Soap12FaultCode
{
public XmlQualifiedName Value;
public Soap12FaultCode Subcode;
}
[XmlType ("Reason", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
internal class Soap12FaultReason
{
[XmlElement ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
public Soap12FaultReasonText [] Texts;
}
[XmlType ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
internal class Soap12FaultReasonText
{
[XmlAttribute ("lang", Namespace = "http://www.w3.org/XML/1998/namespace")]
public string XmlLang;
[XmlText]
public string Value;
}
[XmlType ("Detail", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
internal class Soap12FaultDetail
{
[XmlAnyAttribute]
public XmlAttribute [] Attributes;
[XmlAnyElement]
public XmlElement [] Children;
[XmlText]
public string Text;
}
}

View File

@@ -0,0 +1,55 @@
//
// System.Web.Services.Protocols.HtmlFormParameterReader.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.Web;
using System.Web.Services;
namespace System.Web.Services.Protocols {
public class HtmlFormParameterReader : ValueCollectionParameterReader {
#region Constructors
public HtmlFormParameterReader ()
{
}
#endregion // Constructors
#region Methods
public override object[] Read (HttpRequest request)
{
return Read (request.Form);
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,71 @@
//
// System.Web.Services.Protocols.HtmlFormParameterWriter.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.IO;
using System.Net;
using System.Web.Services;
namespace System.Web.Services.Protocols {
public class HtmlFormParameterWriter : UrlEncodedParameterWriter {
#region Constructors
public HtmlFormParameterWriter ()
{
}
#endregion // Constructors
#region Properties
public override bool UsesWriteRequest {
get { return true; }
}
#endregion // Properties
#region Methods
public override void InitializeRequest (WebRequest request, object[] values)
{
if (RequestEncoding == null) request.ContentType = "application/x-www-form-urlencoded";
else request.ContentType = "application/x-www-form-urlencoded; charset=" + RequestEncoding.BodyName;
}
public override void WriteRequest (Stream requestStream, object[] values)
{
StreamWriter sw = new StreamWriter (requestStream);
Encode (sw, values);
sw.Flush ();
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,62 @@
//
// System.Web.Services.Protocols.HttpGetClientProtocol.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.Net;
using System.Web.Services;
namespace System.Web.Services.Protocols {
public class HttpGetClientProtocol : HttpSimpleClientProtocol {
#region Constructors
public HttpGetClientProtocol ()
{
TypeStub = (HttpSimpleTypeStubInfo) TypeStubManager.GetTypeStub (GetType(), "HttpGet");
}
#endregion // Constructors
#region Methods
protected override WebRequest GetWebRequest (Uri uri)
{
if (uri == null)
throw new InvalidOperationException ("The uri parameter is null.");
if (uri.ToString () == String.Empty)
throw new InvalidOperationException ("The uri parameter has a length of zero.");
WebRequest request = WebRequest.Create (uri);
request.Method = "GET";
return request;
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,62 @@
//
// HttpGetTypeStubInfo.cs: Information about a method and its mapping to a SOAP web service.
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// (C) 2003 Ximian, Inc.
//
//
// 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.
//
namespace System.Web.Services.Protocols
{
internal class HttpGetMethodStubInfo : HttpSimpleMethodStubInfo
{
public HttpGetMethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source): base (parent, source)
{
ParameterReaderType = new MimeFormatterInfo (typeof(UrlParameterReader));
ReturnWriterType = new MimeFormatterInfo (typeof(XmlReturnWriter));
if (ParameterWriterType == null) ParameterWriterType = new MimeFormatterInfo (typeof(UrlParameterWriter));
}
}
internal class HttpGetTypeStubInfo : HttpSimpleTypeStubInfo
{
public HttpGetTypeStubInfo (LogicalTypeInfo logicalTypeInfo): base (logicalTypeInfo)
{
}
public override string ProtocolName
{
get { return "HttpGet"; }
}
protected override MethodStubInfo CreateMethodStubInfo (TypeStubInfo typeInfo, LogicalMethodInfo methodInfo, bool isClientProxy)
{
if (isClientProxy && methodInfo.ActualMethodInfo.GetCustomAttributes (typeof(HttpMethodAttribute),true).Length == 0) return null;
if (!ValueCollectionParameterReader.IsSupported (methodInfo)) return null;
return new HttpGetMethodStubInfo (typeInfo, methodInfo);
}
}
}

View File

@@ -0,0 +1,71 @@
//
// System.Web.Services.Protocols.HttpMethodAttribute.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.
//
namespace System.Web.Services.Protocols {
[AttributeUsage (AttributeTargets.Method, Inherited = true)]
public sealed class HttpMethodAttribute : Attribute {
#region Fields
Type parameterFormatter;
Type returnFormatter;
#endregion
#region Constructors
public HttpMethodAttribute ()
{
}
public HttpMethodAttribute (Type returnFormatter, Type parameterFormatter)
: this ()
{
this.parameterFormatter = parameterFormatter;
this.returnFormatter = returnFormatter;
}
#endregion // Constructors
#region Properties
public Type ParameterFormatter {
get { return parameterFormatter; }
set { parameterFormatter = value; }
}
public Type ReturnFormatter {
get { return returnFormatter; }
set { returnFormatter = value; }
}
#endregion // Properties
}
}

View File

@@ -0,0 +1,62 @@
//
// System.Web.Services.Protocols.HttpPostClientProtocol.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.Net;
using System.Web.Services;
namespace System.Web.Services.Protocols {
public class HttpPostClientProtocol : HttpSimpleClientProtocol {
#region Constructors
public HttpPostClientProtocol ()
{
TypeStub = (HttpSimpleTypeStubInfo) TypeStubManager.GetTypeStub (GetType(), "HttpPost");
}
#endregion // Constructors
#region Methods
protected override WebRequest GetWebRequest (Uri uri)
{
if (null == uri)
throw new InvalidOperationException ("The uri parameter is a null reference.");
if (String.Empty == uri.ToString ())
throw new InvalidOperationException ("The uri parameter has a length of zero.");
WebRequest request = WebRequest.Create (uri);
request.Method = "POST";
return request;
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,62 @@
//
// HttpPostTypeStubInfo.cs: Information about a method and its mapping to a SOAP web service.
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// (C) 2003 Ximian, Inc.
//
//
// 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.
//
namespace System.Web.Services.Protocols
{
internal class HttpPostMethodStubInfo : HttpSimpleMethodStubInfo
{
public HttpPostMethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source): base (parent, source)
{
ParameterReaderType = new MimeFormatterInfo (typeof(HtmlFormParameterReader));
ReturnWriterType = new MimeFormatterInfo (typeof(XmlReturnWriter));
if (ParameterWriterType == null) ParameterWriterType = new MimeFormatterInfo (typeof(HtmlFormParameterWriter));
}
}
internal class HttpPostTypeStubInfo : HttpSimpleTypeStubInfo
{
public HttpPostTypeStubInfo (LogicalTypeInfo logicalTypeInfo): base (logicalTypeInfo)
{
}
public override string ProtocolName
{
get { return "HttpPost"; }
}
protected override MethodStubInfo CreateMethodStubInfo (TypeStubInfo typeInfo, LogicalMethodInfo methodInfo, bool isClientProxy)
{
if (isClientProxy && methodInfo.ActualMethodInfo.GetCustomAttributes (typeof(HttpMethodAttribute),true).Length == 0) return null;
if (!ValueCollectionParameterReader.IsSupported (methodInfo)) return null;
return new HttpPostMethodStubInfo (typeInfo, methodInfo);
}
}
}

View File

@@ -0,0 +1,225 @@
//
// System.Web.Services.Protocols.HttpSimpleClientProtocol.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.Web.Services;
using System.Net;
using System.IO;
using System.Threading;
namespace System.Web.Services.Protocols {
#if NET_2_0
[System.Runtime.InteropServices.ComVisible (true)]
#endif
public abstract class HttpSimpleClientProtocol : HttpWebClientProtocol {
#region Fields
internal HttpSimpleTypeStubInfo TypeStub;
#endregion // Fields
#region Constructors
protected HttpSimpleClientProtocol ()
{
}
#endregion // Constructors
#region Methods
protected IAsyncResult BeginInvoke (string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState)
{
HttpSimpleMethodStubInfo method = (HttpSimpleMethodStubInfo) TypeStub.GetMethod (methodName);
SimpleWebClientAsyncResult ainfo = null;
try
{
MimeParameterWriter parameterWriter = (MimeParameterWriter) method.ParameterWriterType.Create ();
string url = parameterWriter.GetRequestUrl (requestUrl, parameters);
WebRequest req = GetWebRequest (new Uri(url));
ainfo = new SimpleWebClientAsyncResult (req, callback, asyncState);
ainfo.Parameters = parameters;
ainfo.ParameterWriter = parameterWriter;
ainfo.Method = method;
ainfo.Request = req;
ainfo.Request.BeginGetRequestStream (new AsyncCallback (AsyncGetRequestStreamDone), ainfo);
RegisterMapping (asyncState, ainfo);
}
catch (Exception ex)
{
if (ainfo != null)
ainfo.SetCompleted (null, ex, false);
else
throw ex;
}
return ainfo;
}
void AsyncGetRequestStreamDone (IAsyncResult ar)
{
SimpleWebClientAsyncResult ainfo = (SimpleWebClientAsyncResult) ar.AsyncState;
try
{
if (ainfo.ParameterWriter.UsesWriteRequest)
{
Stream stream = ainfo.Request.GetRequestStream ();
ainfo.ParameterWriter.WriteRequest (stream, ainfo.Parameters);
stream.Close ();
}
ainfo.Request.BeginGetResponse (new AsyncCallback (AsyncGetResponseDone), ainfo);
}
catch (Exception ex)
{
ainfo.SetCompleted (null, ex, true);
}
}
void AsyncGetResponseDone (IAsyncResult ar)
{
SimpleWebClientAsyncResult ainfo = (SimpleWebClientAsyncResult) ar.AsyncState;
WebResponse response = null;
try {
response = GetWebResponse (ainfo.Request, ar);
}
catch (WebException ex) {
response = ex.Response;
HttpWebResponse http_response = response as HttpWebResponse;
if (http_response == null || http_response.StatusCode != HttpStatusCode.InternalServerError) {
ainfo.SetCompleted (null, ex, true);
return;
}
}
catch (Exception ex) {
ainfo.SetCompleted (null, ex, true);
return;
}
try {
MimeReturnReader returnReader = (MimeReturnReader) ainfo.Method.ReturnReaderType.Create ();
object result = returnReader.Read (response, response.GetResponseStream ());
ainfo.SetCompleted (result, null, true);
}
catch (Exception ex) {
ainfo.SetCompleted (null, ex, true);
}
}
protected object EndInvoke (IAsyncResult asyncResult)
{
if (!(asyncResult is SimpleWebClientAsyncResult))
throw new ArgumentException ("asyncResult is not the return value from BeginInvoke");
SimpleWebClientAsyncResult ainfo = (SimpleWebClientAsyncResult) asyncResult;
lock (ainfo)
{
if (!ainfo.IsCompleted)
ainfo.WaitForComplete ();
UnregisterMapping (ainfo.AsyncState);
if (ainfo.Exception != null)
throw ainfo.Exception;
else
return ainfo.Result;
}
}
protected object Invoke (string methodName, string requestUrl, object[] parameters)
{
HttpSimpleMethodStubInfo method = (HttpSimpleMethodStubInfo) TypeStub.GetMethod (methodName);
MimeParameterWriter parameterWriter = (MimeParameterWriter) method.ParameterWriterType.Create ();
string url = parameterWriter.GetRequestUrl (requestUrl, parameters);
WebRequest request = GetWebRequest (new Uri(url, true));
parameterWriter.InitializeRequest (request, parameters);
if (parameterWriter.UsesWriteRequest)
{
Stream stream = request.GetRequestStream ();
parameterWriter.WriteRequest (stream, parameters);
stream.Close ();
}
WebResponse response = GetWebResponse (request);
MimeReturnReader returnReader = (MimeReturnReader) method.ReturnReaderType.Create ();
return returnReader.Read (response, response.GetResponseStream ());
}
#if NET_2_0
protected void InvokeAsync (string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback)
{
InvokeAsync (methodName, requestUrl, parameters, callback, null);
}
protected void InvokeAsync (string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback, object userState)
{
InvokeAsyncInfo info = new InvokeAsyncInfo (callback, userState);
BeginInvoke (methodName, requestUrl, parameters, new AsyncCallback (InvokeAsyncCallback), info);
}
void InvokeAsyncCallback (IAsyncResult ar)
{
InvokeAsyncInfo info = (InvokeAsyncInfo) ar.AsyncState;
SimpleWebClientAsyncResult sar = (SimpleWebClientAsyncResult) ar;
InvokeCompletedEventArgs args = new InvokeCompletedEventArgs (sar.Exception, false, info.UserState, (object[]) sar.Result);
if (info.Context != null)
info.Context.Send (info.Callback, args);
else
info.Callback (args);
}
#endif
#endregion // Methods
}
internal class SimpleWebClientAsyncResult : WebClientAsyncResult
{
public SimpleWebClientAsyncResult (WebRequest request, AsyncCallback callback, object asyncState)
: base (request, callback, asyncState)
{
}
public object[] Parameters;
public HttpSimpleMethodStubInfo Method;
public MimeParameterWriter ParameterWriter;
}
}

View File

@@ -0,0 +1,147 @@
//
// HttpSimpleMethodStubInfo.cs: Information about a method and its mapping to a SOAP web service.
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// (C) 2003 Ximian, Inc.
//
//
// 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.Reflection;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using System.Web.Services;
using System.Web.Services.Description;
namespace System.Web.Services.Protocols
{
enum FormatterKind
{
ParameterWriter,
ParameterReader,
ReturnReader,
ReturnWriter
}
internal abstract class HttpSimpleMethodStubInfo : MethodStubInfo
{
public MimeFormatterInfo ParameterWriterType;
public MimeFormatterInfo ParameterReaderType;
public MimeFormatterInfo ReturnReaderType;
public MimeFormatterInfo ReturnWriterType;
public MimeFormatterInfo GetFormatterInfo (FormatterKind kind)
{
switch (kind)
{
case FormatterKind.ParameterWriter: return ParameterWriterType;
case FormatterKind.ParameterReader: return ParameterReaderType;
case FormatterKind.ReturnReader: return ReturnReaderType;
case FormatterKind.ReturnWriter: return ReturnWriterType;
}
return null;
}
public HttpSimpleMethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source): base (parent, source)
{
object[] atts = source.CustomAttributeProvider.GetCustomAttributes (typeof(HttpMethodAttribute), true);
if (atts.Length > 0)
{
HttpMethodAttribute at = (HttpMethodAttribute) atts[0];
ParameterWriterType = new MimeFormatterInfo (at.ParameterFormatter);
ReturnReaderType = new MimeFormatterInfo (at.ReturnFormatter);
}
if (ReturnReaderType == null) {
if (source.IsVoid) ReturnReaderType = new MimeFormatterInfo (typeof(NopReturnReader));
else ReturnReaderType = new MimeFormatterInfo (typeof(XmlReturnReader));
}
}
}
internal class MimeFormatterInfo
{
public MimeFormatterInfo (Type type) {
Type = type;
}
public MimeFormatter Create () {
return MimeFormatter.CreateInstance (Type, Initializer);
}
public Type Type;
public object Initializer;
}
internal abstract class HttpSimpleTypeStubInfo : TypeStubInfo
{
public HttpSimpleTypeStubInfo (LogicalTypeInfo logicalTypeInfo): base (logicalTypeInfo)
{
}
protected override void BuildTypeMethods ()
{
base.BuildTypeMethods ();
BuildInitializers (FormatterKind.ParameterWriter);
BuildInitializers (FormatterKind.ParameterReader);
BuildInitializers (FormatterKind.ReturnReader);
BuildInitializers (FormatterKind.ReturnWriter);
}
void BuildInitializers (FormatterKind formatter)
{
Hashtable types = new Hashtable ();
foreach (HttpSimpleMethodStubInfo met in Methods)
AddType (types, met.GetFormatterInfo (formatter).Type, met);
foreach (DictionaryEntry ent in types)
{
Type t = (Type)ent.Key;
ArrayList list = (ArrayList)ent.Value;
LogicalMethodInfo[] mets = new LogicalMethodInfo [list.Count];
for (int n=0; n<list.Count; n++)
mets[n] = ((MethodStubInfo)list[n]).MethodInfo;
object[] inits = MimeFormatter.GetInitializers (t, mets);
for (int n=0; n<list.Count; n++)
((HttpSimpleMethodStubInfo)list[n]).GetFormatterInfo (formatter).Initializer = inits[n];
}
}
void AddType (Hashtable types, Type type, HttpSimpleMethodStubInfo method)
{
ArrayList list = (ArrayList) types [type];
if (list == null)
{
list = new ArrayList ();
types [type] = list;
}
list.Add (method);
}
}
}

View File

@@ -0,0 +1,135 @@
//
// System.Web.Services.Protocols.HttpSimpleWebServiceHandler.cs
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) Ximian, Inc. 2003
//
//
// 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.Reflection;
using System.IO;
using System.Web.Services;
namespace System.Web.Services.Protocols
{
internal class HttpSimpleWebServiceHandler: WebServiceHandler
{
HttpSimpleTypeStubInfo _typeInfo;
HttpSimpleMethodStubInfo method;
public HttpSimpleWebServiceHandler (Type type, string protocolName)
: base (type)
{
_typeInfo = (HttpSimpleTypeStubInfo) TypeStubManager.GetTypeStub (type, protocolName);
}
protected HttpSimpleTypeStubInfo TypeStub
{
get { return _typeInfo; }
}
internal override MethodStubInfo GetRequestMethod (HttpContext context)
{
string name = context.Request.PathInfo;
if (name.StartsWith ("/"))
name = name.Substring (1);
method = (HttpSimpleMethodStubInfo) _typeInfo.GetMethod (name);
if (method == null)
WriteError (context, "Method " + name + " not defined in service " + ServiceType.Name);
return method;
}
public override void ProcessRequest (HttpContext context)
{
Context = context;
Stream respStream = null;
Exception error = null;
try
{
if (method == null)
method = (HttpSimpleMethodStubInfo) GetRequestMethod (context);
if (method.MethodInfo.EnableSession)
Session = context.Session;
MimeParameterReader parameterReader = (MimeParameterReader) method.ParameterReaderType.Create ();
object[] parameters = parameterReader.Read (context.Request);
MimeReturnWriter returnWriter = (MimeReturnWriter) method.ReturnWriterType.Create ();
object result = Invoke (method.MethodInfo, parameters);
respStream = context.Response.OutputStream;
returnWriter.Write (context.Response, respStream, result);
}
catch (Exception ex)
{
error = ex;
}
if (error != null)
WriteError (context, error.ToString ());
if (respStream != null)
respStream.Close ();
}
void WriteError (HttpContext context, string msg)
{
try
{
context.Response.ContentType = "text/plain";
context.Response.StatusCode = 500;
context.Response.Write (msg);
context.Response.End ();
}
catch {}
}
object Invoke (LogicalMethodInfo method, object[] parameters)
{
try
{
object server = CreateServerInstance ();
try {
object[] res = method.Invoke (server, parameters);
if (!method.IsVoid) return res[0];
else return null;
}
finally {
IDisposable disp = server as IDisposable;
if (disp != null)
disp.Dispose();
}
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
}
}

View File

@@ -0,0 +1,425 @@
//
// System.Web.Services.Protocols.HttpSoapWebServiceHandler.cs
//
// Author:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) Ximian, Inc. 2003
//
//
// 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.Net;
using System.Web;
using System.Xml;
using System.Text;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
#if !MOBILE
using System.Web.Services.Description;
#endif
namespace System.Web.Services.Protocols
{
internal class HttpSoapWebServiceHandler: WebServiceHandler
{
SoapTypeStubInfo _typeStubInfo;
SoapExtension[] _extensionChainHighPrio;
SoapExtension[] _extensionChainMedPrio;
SoapExtension[] _extensionChainLowPrio;
SoapMethodStubInfo methodInfo;
SoapServerMessage requestMessage = null;
public HttpSoapWebServiceHandler (Type type): base (type)
{
_typeStubInfo = (SoapTypeStubInfo) TypeStubManager.GetTypeStub (ServiceType, "Soap");
}
public override bool IsReusable
{
get { return false; }
}
internal override MethodStubInfo GetRequestMethod (HttpContext context)
{
try
{
requestMessage = DeserializeRequest (context);
return methodInfo;
}
catch (Exception ex)
{
SerializeFault (context, requestMessage, ex);
return null;
}
}
public override void ProcessRequest (HttpContext context)
{
Context = context;
SoapServerMessage responseMessage = null;
try
{
if (requestMessage == null) {
requestMessage = DeserializeRequest (context);
}
if (methodInfo != null && methodInfo.OneWay) {
context.Response.BufferOutput = false;
context.Response.StatusCode = 202;
context.Response.Flush ();
context.Response.Close ();
Invoke (context, requestMessage);
} else {
responseMessage = Invoke (context, requestMessage);
SerializeResponse (context.Response, responseMessage);
}
}
catch (Exception ex)
{
if (methodInfo != null && methodInfo.OneWay) {
context.Response.StatusCode = 500;
context.Response.Flush ();
context.Response.Close ();
} else {
SerializeFault (context, requestMessage, ex);
}
}
finally {
IDisposable disp = requestMessage.Server as IDisposable;
requestMessage = null;
if (disp != null)
disp.Dispose();
}
}
SoapServerMessage DeserializeRequest (HttpContext context)
{
HttpRequest request = context.Request;
Stream stream = request.InputStream;
//using (stream)
//{
string soapAction = null;
string ctype;
Encoding encoding = WebServiceHelper.GetContentEncoding (request.ContentType, out ctype);
#if NET_2_0
if (ctype != "text/xml" && ctype != "application/soap+xml")
#else
if (ctype != "text/xml")
#endif
throw new WebException ("Content is not XML: " + ctype);
object server = CreateServerInstance ();
SoapServerMessage message = new SoapServerMessage (request, server, stream);
message.SetStage (SoapMessageStage.BeforeDeserialize);
message.ContentType = ctype;
#if NET_2_0
object soapVer = context.Items ["WebServiceSoapVersion"];
if (soapVer != null)
message.SetSoapVersion ((SoapProtocolVersion) soapVer);
#endif
// If the routing style is SoapAction, then we can get the method information now
// and set it to the SoapMessage
if (_typeStubInfo.RoutingStyle == SoapServiceRoutingStyle.SoapAction)
{
string headerName = message.IsSoap12 ? "action" : "SOAPAction";
soapAction = message.IsSoap12 ? WebServiceHelper.GetContextAction(request.ContentType) : request.Headers [headerName];
if (soapAction == null) {
if (!message.IsSoap12)
throw new SoapException ("Missing SOAPAction header", WebServiceHelper.ClientFaultCode (message.IsSoap12));
}
else
{
methodInfo = _typeStubInfo.GetMethodForSoapAction (soapAction);
if (methodInfo == null) throw new SoapException ("Server did not recognize the value of HTTP header " + headerName + ": " + soapAction, WebServiceHelper.ClientFaultCode (message.IsSoap12));
message.MethodStubInfo = methodInfo;
}
}
// Execute the high priority global extensions. Do not try to execute the medium and
// low priority extensions because if the routing style is RequestElement we still
// don't have method information
_extensionChainHighPrio = SoapExtension.CreateExtensionChain (_typeStubInfo.SoapExtensions[0]);
stream = SoapExtension.ExecuteChainStream (_extensionChainHighPrio, stream);
SoapExtension.ExecuteProcessMessage (_extensionChainHighPrio, message, stream, false);
// If the routing style is RequestElement, try to get the method name from the
// stream processed by the high priority extensions
if (_typeStubInfo.RoutingStyle == SoapServiceRoutingStyle.RequestElement || (message.IsSoap12 && soapAction == null))
{
MemoryStream mstream;
byte[] buffer = null;
if (stream.CanSeek)
{
buffer = new byte [stream.Length];
for (int n=0; n<stream.Length;)
n += stream.Read (buffer, n, (int)stream.Length-n);
mstream = new MemoryStream (buffer);
}
else
{
buffer = new byte [500];
mstream = new MemoryStream ();
int len;
while ((len = stream.Read (buffer, 0, 500)) > 0)
mstream.Write (buffer, 0, len);
mstream.Position = 0;
buffer = mstream.ToArray ();
}
soapAction = ReadActionFromRequestElement (new MemoryStream (buffer), encoding, message.IsSoap12);
stream = mstream;
methodInfo = (SoapMethodStubInfo) _typeStubInfo.GetMethod (soapAction);
message.MethodStubInfo = methodInfo;
}
// Whatever routing style we used, we should now have the method information.
// We can now notify the remaining extensions
if (methodInfo == null) throw new SoapException ("Method '" + soapAction + "' not defined in the web service '" + _typeStubInfo.LogicalType.WebServiceName + "'", WebServiceHelper.ClientFaultCode (message.IsSoap12));
_extensionChainMedPrio = SoapExtension.CreateExtensionChain (methodInfo.SoapExtensions);
_extensionChainLowPrio = SoapExtension.CreateExtensionChain (_typeStubInfo.SoapExtensions[1]);
stream = SoapExtension.ExecuteChainStream (_extensionChainMedPrio, stream);
stream = SoapExtension.ExecuteChainStream (_extensionChainLowPrio, stream);
SoapExtension.ExecuteProcessMessage (_extensionChainMedPrio, message, stream, false);
SoapExtension.ExecuteProcessMessage (_extensionChainLowPrio, message, stream, false);
// Deserialize the request
StreamReader reader = new StreamReader (stream, encoding, false);
XmlTextReader xmlReader = new XmlTextReader (reader);
try
{
object content;
SoapHeaderCollection headers;
WebServiceHelper.ReadSoapMessage (xmlReader, methodInfo, SoapHeaderDirection.In, message.IsSoap12, out content, out headers);
message.InParameters = (object []) content;
message.SetHeaders (headers);
}
catch (Exception ex)
{
throw new SoapException ("Could not deserialize Soap message", WebServiceHelper.ClientFaultCode (message.IsSoap12), ex);
}
// Notify the extensions after deserialization
message.SetStage (SoapMessageStage.AfterDeserialize);
SoapExtension.ExecuteProcessMessage (_extensionChainHighPrio, message, stream, false);
SoapExtension.ExecuteProcessMessage (_extensionChainMedPrio, message, stream, false);
SoapExtension.ExecuteProcessMessage (_extensionChainLowPrio, message, stream, false);
return message;
//}
}
string ReadActionFromRequestElement (Stream stream, Encoding encoding, bool soap12)
{
string envNS = soap12 ?
WebServiceHelper.Soap12EnvelopeNamespace :
WebServiceHelper.SoapEnvelopeNamespace;
try
{
StreamReader reader = new StreamReader (stream, encoding, false);
XmlTextReader xmlReader = new XmlTextReader (reader);
xmlReader.MoveToContent ();
xmlReader.ReadStartElement ("Envelope", envNS);
while (! (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == envNS))
xmlReader.Skip ();
xmlReader.ReadStartElement ("Body", envNS);
xmlReader.MoveToContent ();
return xmlReader.LocalName;
}
catch (Exception ex)
{
string errmsg = "The root element for the request could not be determined. ";
errmsg += "When RoutingStyle is set to RequestElement, SoapExtensions configured ";
errmsg += "via an attribute on the method cannot modify the request stream before it is read. ";
errmsg += "The extension must be configured via the SoapExtensionTypes element in web.config ";
errmsg += "or the request must arrive at the server as clear text.";
throw new SoapException (errmsg, WebServiceHelper.ServerFaultCode (soap12), ex);
}
}
void SerializeResponse (HttpResponse response, SoapServerMessage message)
{
SoapMethodStubInfo methodInfo = message.MethodStubInfo;
if ((message.ContentEncoding != null) && (message.ContentEncoding.Length > 0))
response.AppendHeader("Content-Encoding", message.ContentEncoding);
response.ContentType = message.IsSoap12 ?
"application/soap+xml; charset=utf-8" :
"text/xml; charset=utf-8";
if (message.Exception != null) response.StatusCode = 500;
Stream responseStream = response.OutputStream;
Stream outStream = responseStream;
bool bufferResponse = (methodInfo == null || methodInfo.MethodAttribute.BufferResponse);
response.BufferOutput = bufferResponse;
try
{
// While serializing, process extensions in reverse order
if (bufferResponse)
{
outStream = SoapExtension.ExecuteChainStream (_extensionChainHighPrio, outStream);
outStream = SoapExtension.ExecuteChainStream (_extensionChainMedPrio, outStream);
outStream = SoapExtension.ExecuteChainStream (_extensionChainLowPrio, outStream);
message.SetStage (SoapMessageStage.BeforeSerialize);
SoapExtension.ExecuteProcessMessage (_extensionChainLowPrio, message, outStream, true);
SoapExtension.ExecuteProcessMessage (_extensionChainMedPrio, message, outStream, true);
SoapExtension.ExecuteProcessMessage (_extensionChainHighPrio, message, outStream, true);
}
XmlTextWriter xtw = WebServiceHelper.CreateXmlWriter (outStream);
if (message.Exception == null)
WebServiceHelper.WriteSoapMessage (xtw, methodInfo, SoapHeaderDirection.Out, message.OutParameters, message.Headers, message.IsSoap12);
else if (methodInfo != null) {
#if NET_2_0
if (message.IsSoap12)
WebServiceHelper.WriteSoapMessage (xtw, methodInfo, SoapHeaderDirection.Fault, new Soap12Fault (message.Exception), message.Headers, message.IsSoap12);
else
#endif
{
WebServiceHelper.WriteSoapMessage (xtw, methodInfo, SoapHeaderDirection.Fault, new Fault (message.Exception), message.Headers, message.IsSoap12);
}
}
else {
#if NET_2_0
if (message.IsSoap12)
WebServiceHelper.WriteSoapMessage (xtw, SoapBindingUse.Literal, Soap12Fault.Serializer, null, new Soap12Fault (message.Exception), null, message.IsSoap12);
else
#endif
{
WebServiceHelper.WriteSoapMessage (xtw, SoapBindingUse.Literal, Fault.Serializer, null, new Fault (message.Exception), null, message.IsSoap12);
}
}
if (bufferResponse)
{
message.SetStage (SoapMessageStage.AfterSerialize);
SoapExtension.ExecuteProcessMessage (_extensionChainLowPrio, message, outStream, true);
SoapExtension.ExecuteProcessMessage (_extensionChainMedPrio, message, outStream, true);
SoapExtension.ExecuteProcessMessage (_extensionChainHighPrio, message, outStream, true);
}
xtw.Flush ();
}
catch (Exception ex)
{
// If the response is buffered, we can discard the response and
// serialize a new Fault message as response.
if (bufferResponse) throw ex;
// If it is not buffered, we can't rollback what has been sent,
// so we can only close the connection and return.
responseStream.Close ();
return;
}
}
void SerializeFault (HttpContext context, SoapServerMessage requestMessage, Exception ex)
{
SoapException soex = ex as SoapException;
if (soex == null) soex = new SoapException (ex.ToString (), WebServiceHelper.ServerFaultCode (requestMessage != null && requestMessage.IsSoap12), ex);
SoapServerMessage faultMessage;
if (requestMessage != null)
faultMessage = new SoapServerMessage (context.Request, soex, requestMessage.MethodStubInfo, requestMessage.Server, requestMessage.Stream);
else
faultMessage = new SoapServerMessage (context.Request, soex, null, null, null);
#if NET_2_0
object soapVer = context.Items ["WebServiceSoapVersion"];
if (soapVer != null)
faultMessage.SetSoapVersion ((SoapProtocolVersion) soapVer);
#endif
SerializeResponse (context.Response, faultMessage);
context.Response.End ();
return;
}
private SoapServerMessage Invoke (HttpContext ctx, SoapServerMessage requestMessage)
{
SoapMethodStubInfo methodInfo = requestMessage.MethodStubInfo;
// Assign header values to web service members
requestMessage.UpdateHeaderValues (requestMessage.Server, methodInfo.Headers);
// Fill an array with the input parameters at the right position
object[] parameters = new object[methodInfo.MethodInfo.Parameters.Length];
ParameterInfo[] inParams = methodInfo.MethodInfo.InParameters;
for (int n=0; n<inParams.Length; n++)
parameters [inParams[n].Position] = requestMessage.InParameters [n];
// Invoke the method
try
{
object[] results = methodInfo.MethodInfo.Invoke (requestMessage.Server, parameters);
requestMessage.OutParameters = results;
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
// Check that headers with MustUnderstand flag have been understood
foreach (SoapHeader header in requestMessage.Headers)
{
if (header.MustUnderstand && !header.DidUnderstand)
throw new SoapHeaderException ("Header not understood: " + header.GetType(), WebServiceHelper.MustUnderstandFaultCode (requestMessage.IsSoap12));
}
// Collect headers that must be sent to the client
requestMessage.CollectHeaders (requestMessage.Server, methodInfo.Headers, SoapHeaderDirection.Out);
return requestMessage;
}
}
}

View File

@@ -0,0 +1,262 @@
//
// System.Web.Services.Protocols.HttpWebClientProtocol.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2002
//
//
// 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.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Web.Services;
using System.Collections;
namespace System.Web.Services.Protocols {
#if NET_2_0
[System.Runtime.InteropServices.ComVisible (true)]
#endif
public abstract class HttpWebClientProtocol : WebClientProtocol {
#region Fields
bool allowAutoRedirect, enableDecompression;
X509CertificateCollection clientCertificates;
CookieContainer cookieContainer;
IWebProxy proxy;
string userAgent;
bool _unsafeAuthenticated;
#endregion
#region Constructors
protected HttpWebClientProtocol ()
{
allowAutoRedirect = false;
clientCertificates = null;
cookieContainer = null;
proxy = null; // FIXME
userAgent = String.Format ("Mono Web Services Client Protocol {0}", Environment.Version);
}
#endregion // Constructors
#region Properties
[DefaultValue (false)]
[WebServicesDescription ("Enable automatic handling of server redirects.")]
public bool AllowAutoRedirect {
get { return allowAutoRedirect; }
set { allowAutoRedirect = value; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[WebServicesDescription ("The client certificates that will be sent to the server, if the server requests them.")]
public X509CertificateCollection ClientCertificates {
get {
if (clientCertificates == null)
clientCertificates = new X509CertificateCollection ();
return clientCertificates;
}
}
[DefaultValue (null)]
[WebServicesDescription ("A container for all cookies received from servers in the current session.")]
public CookieContainer CookieContainer {
get { return cookieContainer; }
set { cookieContainer = value; }
}
#if NET_2_0
[DefaultValue (false)]
public bool EnableDecompression {
get { return enableDecompression; }
set { enableDecompression = value; }
}
#endif
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public IWebProxy Proxy {
get { return proxy; }
set { proxy = value; }
}
[WebServicesDescription ("Sets the user agent http header for the request.")]
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public string UserAgent {
get { return userAgent; }
set { userAgent = value; }
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public bool UnsafeAuthenticatedConnectionSharing
{
get { return _unsafeAuthenticated; }
set { _unsafeAuthenticated = value; }
}
#endregion // Properties
#region Methods
internal virtual void CheckForCookies (HttpWebResponse response)
{
CookieCollection cookies = response.Cookies;
if (cookieContainer == null || cookies.Count == 0)
return;
CookieCollection coll = cookieContainer.GetCookies (uri);
foreach (Cookie c in cookies) {
bool add = true;
foreach (Cookie prev in coll) {
if (c.Equals (prev)) {
add = false;
break;
}
}
if (add)
cookieContainer.Add (c);
}
}
protected override WebRequest GetWebRequest (Uri uri)
{
WebRequest req = base.GetWebRequest (uri);
HttpWebRequest request = req as HttpWebRequest;
if (request == null)
return req;
if (enableDecompression)
request.AutomaticDecompression = DecompressionMethods.GZip;
request.AllowAutoRedirect = allowAutoRedirect;
if (clientCertificates != null)
request.ClientCertificates.AddRange (clientCertificates);
request.CookieContainer = cookieContainer;
if (proxy != null)
request.Proxy = proxy;
request.UserAgent = userAgent;
return request;
}
protected override WebResponse GetWebResponse (WebRequest request)
{
WebResponse response = base.GetWebResponse (request);
HttpWebResponse wr = response as HttpWebResponse;
if (wr != null)
CheckForCookies (wr);
return response;
}
protected override WebResponse GetWebResponse (WebRequest request, IAsyncResult result)
{
WebResponse response = base.GetWebResponse (request, result);
HttpWebResponse wr = response as HttpWebResponse;
if (wr != null)
CheckForCookies (wr);
return response;
}
#if NET_2_0
Hashtable mappings = new Hashtable ();
internal void RegisterMapping (object userState, WebClientAsyncResult result)
{
if (userState == null)
userState = typeof (string);
mappings [userState] = result;
}
internal void UnregisterMapping (object userState)
{
if (userState == null)
userState = typeof (string);
mappings.Remove (userState);
}
protected void CancelAsync (object userState)
{
WebClientAsyncResult result = (WebClientAsyncResult) mappings [userState];
if (result == null)
return;
mappings.Remove (userState);
result.Abort ();
}
[MonoTODO]
public static bool GenerateXmlMappings (Type type, ArrayList mapping)
{
throw new NotImplementedException ();
}
[MonoTODO]
public static Hashtable GenerateXmlMappings (Type[] types, ArrayList mapping)
{
throw new NotImplementedException ();
}
#else
internal void UnregisterMapping (object userState)
{
}
internal void RegisterMapping (object userState, WebClientAsyncResult result)
{
}
#endif
#endregion // Methods
}
#if NET_2_0
internal class InvokeAsyncInfo
{
public SynchronizationContext Context;
public object UserState;
public SendOrPostCallback Callback;
public InvokeAsyncInfo (SendOrPostCallback callback, object userState)
{
Callback = callback;
UserState = userState;
Context = SynchronizationContext.Current;
}
}
#endif
}

View File

@@ -0,0 +1,53 @@
//
// System.Web.Services.Protocols.InvokeCompletedEventArgs.cs
//
// Author:
// Lluis Sanchez (lluis@novell.com)
//
// Copyright (C) Novell, Inc., 2004
//
//
// 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.
//
#if NET_2_0
using System.ComponentModel;
namespace System.Web.Services.Protocols
{
public class InvokeCompletedEventArgs : AsyncCompletedEventArgs
{
object[] _results;
internal InvokeCompletedEventArgs (Exception error, bool cancelled, object userState, object[] results)
: base (error, cancelled, userState)
{
_results = results;
}
public object[] Results {
get { return _results; }
}
}
}
#endif

View File

@@ -0,0 +1,41 @@
//
// System.Web.Services.Protocols.InvokeCompletedEventHandler.cs
//
// Author:
// Lluis Sanchez (lluis@novell.com)
//
// Copyright (C) Novell, Inc., 2004
//
//
// 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.
//
#if NET_2_0
namespace System.Web.Services.Protocols
{
public delegate void InvokeCompletedEventHandler (
object sender,
InvokeCompletedEventArgs e
);
}
#endif

View File

@@ -0,0 +1,476 @@
//
// System.Web.Services.Protocols.LogicalMethodInfo.cs
//
// Authors:
// Miguel de Icaza (miguel@ximian.com)
// Tim Coleman (tim@timcoleman.com)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) Tim Coleman, 2002
// Copyright (C) Ximian, Inc, 2003
//
// TODO:
// BeginInvoke, EndInvoke are missing.
// AsyncResultParameter
//
// WILD GUESS:
// The reason for this class is so that it can cluster method/begin/end methods
// together, as the begin/end methods in generated files from WSDL does *NOT*
// contain all the information required to make a request.
//
// Either that, or the Begin*/End* versions probe the attributes on the regular
// method (which seems simpler).
//
//
// 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.Reflection;
using System.Collections;
using System.Text;
using System.Web.Services;
namespace System.Web.Services.Protocols {
public sealed class LogicalMethodInfo {
#region Fields
MethodInfo method_info, end_method_info;
ParameterInfo [] parameters;
ParameterInfo [] out_parameters;
ParameterInfo [] in_parameters;
WebMethodAttribute attribute;
#endregion // Fields.
#region Constructors
public LogicalMethodInfo (MethodInfo method_info)
{
if (method_info == null)
throw new ArgumentNullException ("method_info should be non-null");
if (method_info.IsStatic)
throw new InvalidOperationException ("method is static");
this.method_info = method_info;
}
//
// Only an internal contructor, called from "Create"
//
LogicalMethodInfo (MethodInfo method_info, MethodInfo end_method_info)
{
if (method_info == null)
throw new ArgumentNullException ("method_info should be non-null");
if (method_info.IsStatic)
throw new InvalidOperationException ("method is static");
this.method_info = method_info;
this.end_method_info = end_method_info;
}
#endregion // Constructors
#region Properties
//
// Signatures for Begin/End methods:
//
// public System.IAsyncResult BeginHelloWorld(ARG1, ARG2, System.AsyncCallback callback, object asyncState) {
// public string EndHelloWorld(System.IAsyncResult asyncResult) {
public ParameterInfo AsyncCallbackParameter {
get {
ParameterInfo [] pi = method_info.GetParameters ();
return pi [pi.Length-2];
}
}
public ParameterInfo AsyncResultParameter {
get {
ParameterInfo [] pi = end_method_info.GetParameters ();
return pi [pi.Length-1];
}
}
public ParameterInfo AsyncStateParameter {
get {
ParameterInfo [] pi = method_info.GetParameters ();
return pi [pi.Length-1];
}
}
public MethodInfo BeginMethodInfo {
get {
if (IsBeginMethod (method_info))
return method_info;
return null;
}
}
public ICustomAttributeProvider CustomAttributeProvider {
get {
return method_info;
}
}
public Type DeclaringType {
get {
return method_info.DeclaringType;
}
}
public MethodInfo EndMethodInfo {
get {
return end_method_info;
}
}
public ParameterInfo[] InParameters {
get {
if (parameters == null)
ComputeParameters ();
return in_parameters;
}
}
public bool IsAsync {
get {
return end_method_info != null;
}
}
public bool IsVoid {
get {
return ReturnType == typeof (void);
}
}
public MethodInfo MethodInfo {
get {
if (IsBeginMethod (method_info))
return null;
return method_info;
}
}
public string Name {
get {
return method_info.Name;
}
}
internal MethodInfo ActualMethodInfo {
get { return method_info; }
}
void ComputeParameters ()
{
ParameterInfo[] pars = method_info.GetParameters ();
if (IsAsync)
{
parameters = new ParameterInfo [pars.Length - 2];
Array.Copy (pars, 0, parameters, 0, pars.Length - 2);
in_parameters = new ParameterInfo [parameters.Length];
parameters.CopyTo (in_parameters, 0);
ParameterInfo[] outPars = end_method_info.GetParameters ();
out_parameters = new ParameterInfo [outPars.Length - 1];
Array.Copy (outPars, 0, out_parameters, 0, out_parameters.Length);
}
else
{
parameters = pars;
int out_count = 0;
int in_count = 0;
foreach (ParameterInfo p in parameters){
Type ptype = p.ParameterType;
if (ptype.IsByRef){
out_count++;
if (!p.IsOut)
in_count++;
} else
in_count++;
}
out_parameters = new ParameterInfo [out_count];
int i = 0;
for (int j = 0; j < parameters.Length; j++){
if (parameters [j].ParameterType.IsByRef)
out_parameters [i++] = parameters [j];
}
in_parameters = new ParameterInfo [in_count];
i = 0;
for (int j = 0; j < parameters.Length; j++){
if (parameters [j].ParameterType.IsByRef){
if (!parameters [j].IsOut)
in_parameters [i++] = parameters [j];
} else
in_parameters [i++] = parameters [j];
}
}
}
public ParameterInfo[] OutParameters {
get {
if (parameters == null)
ComputeParameters ();
return out_parameters;
}
}
public ParameterInfo[] Parameters {
get {
if (parameters == null)
ComputeParameters ();
return parameters;
}
}
public Type ReturnType {
get {
if (IsAsync)
return end_method_info.ReturnType;
else
return method_info.ReturnType;
}
}
public ICustomAttributeProvider ReturnTypeCustomAttributeProvider {
get {
return method_info.ReturnTypeCustomAttributes;
}
}
internal bool EnableSession {
get {
if (method_info == null)
return false;
if (attribute == null) {
object [] o = method_info.GetCustomAttributes (false);
foreach (Attribute att in o) {
if (att is WebMethodAttribute) {
attribute = (WebMethodAttribute) att;
break;
}
}
}
return (attribute != null) ? attribute.EnableSession : false;
}
}
internal int CacheDuration {
get {
if (method_info == null)
return -1;
if (attribute == null) {
object [] o = method_info.GetCustomAttributes (false);
foreach (Attribute att in o) {
if (att is WebMethodAttribute) {
attribute = (WebMethodAttribute) att;
break;
}
}
}
return (attribute != null) ? attribute.CacheDuration : -1;
}
}
#endregion // Properties
#region Methods
public IAsyncResult BeginInvoke (object target, object[] values, AsyncCallback callback, object asyncState)
{
int len = (values!=null) ? values.Length : 0;
object[] pars = new object [len + 2];
if (len > 0)
values.CopyTo (pars, 0);
pars [len] = callback;
pars [len+1] = asyncState;
return (IAsyncResult) method_info.Invoke (target, pars);
}
public static LogicalMethodInfo[] Create (MethodInfo[] method_infos)
{
return Create (method_infos, LogicalMethodTypes.Sync | LogicalMethodTypes.Async);
}
public static LogicalMethodInfo[] Create (MethodInfo[] method_infos, LogicalMethodTypes types)
{
ArrayList sync = ((types & LogicalMethodTypes.Sync) != 0) ? new ArrayList () : null;
ArrayList begin, end;
if ((types & LogicalMethodTypes.Async) != 0){
begin = new ArrayList ();
end = new ArrayList ();
} else
begin = end = null;
foreach (MethodInfo mi in method_infos){
if (IsBeginMethod (mi) && begin != null)
begin.Add (mi);
else if (IsEndMethod (mi) && end != null)
end.Add (mi);
else if (sync != null)
sync.Add (mi);
}
int bcount = 0, count = 0;
if (begin != null){
bcount = count = begin.Count;
if (count != end.Count)
throw new InvalidOperationException ("Imbalance of begin/end methods");
}
if (sync != null)
count += sync.Count;
LogicalMethodInfo [] res = new LogicalMethodInfo [count];
int dest = 0;
if (begin != null){
foreach (MethodInfo bm in begin){
string end_name = "End" + bm.Name.Substring (5);
for (int i = 0; i < bcount; i++){
MethodInfo em = (MethodInfo) end [i];
if (em.Name == end_name){
res [dest++] = new LogicalMethodInfo (bm, em);
break;
}
throw new InvalidOperationException ("Imbalance of begin/end methods");
}
}
}
if (sync != null)
foreach (MethodInfo mi in sync){
res [dest++] = new LogicalMethodInfo (mi);
}
return res;
}
public object[] EndInvoke (object target, IAsyncResult asyncResult)
{
if (parameters == null)
ComputeParameters ();
object[] values = new object [out_parameters.Length + 1];
values [values.Length - 1] = asyncResult;
object res = end_method_info.Invoke (target, values);
int retc = IsVoid ? 0 : 1;
object [] ret = new object [retc + out_parameters.Length];
if (retc == 1) ret [0] = res;
Array.Copy (values, 0, ret, retc, out_parameters.Length);
return ret;
}
public object GetCustomAttribute (Type type)
{
return Attribute.GetCustomAttribute (method_info, type, false);
}
public object[] GetCustomAttributes (Type type)
{
return method_info.GetCustomAttributes (type, false);
}
public object[] Invoke (object target, object[] values)
{
if (parameters == null)
ComputeParameters ();
int retc = IsVoid ? 0 : 1;
object [] ret = new object [retc + out_parameters.Length];
object res = method_info.Invoke (target, values);
if (retc == 1) ret [0] = res;
int j = retc;
for (int i = 0; i < parameters.Length; i++){
if (parameters [i].ParameterType.IsByRef)
ret [j++] = values [i];
}
return ret;
}
public static bool IsBeginMethod (MethodInfo method_info)
{
if (method_info == null)
throw new ArgumentNullException ("method_info can not be null");
if (method_info.ReturnType != typeof (IAsyncResult))
return false;
if (method_info.Name.StartsWith ("Begin"))
return true;
return false;
}
public static bool IsEndMethod (MethodInfo method_info)
{
if (method_info == null)
throw new ArgumentNullException ("method_info can not be null");
ParameterInfo [] parameter_info = method_info.GetParameters ();
if (parameter_info.Length != 1)
return false;
if (parameter_info [0].ParameterType != typeof (IAsyncResult))
return false;
if (method_info.Name.StartsWith ("End"))
return true;
return false;
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
if (parameters == null)
ComputeParameters ();
for (int i = 0; i < parameters.Length; i++){
sb.Append (parameters [i].ParameterType);
if (parameters [i].ParameterType.IsByRef)
sb.Append (" ByRef");
if (i+1 != parameters.Length)
sb.Append (", ");
}
return String.Format (
"{0} {1} ({2})",
method_info.ReturnType, method_info.Name,
sb.ToString ());
}
#endregion // Methods
}
}

Some files were not shown because too many files have changed in this diff Show More