Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@ -0,0 +1,43 @@
//------------------------------------------------------------------------------
// <copyright file="AnyReturnReader.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.IO;
using System;
using System.Web.Services;
using System.Net;
/// <include file='doc\AnyReturnReader.uex' path='docs/doc[@for="AnyReturnReader"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class AnyReturnReader : MimeReturnReader {
/// <include file='doc\AnyReturnReader.uex' path='docs/doc[@for="AnyReturnReader.Initialize"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override void Initialize(object o) {
}
/// <include file='doc\AnyReturnReader.uex' path='docs/doc[@for="AnyReturnReader.GetInitializer"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override object GetInitializer(LogicalMethodInfo methodInfo) {
if (methodInfo.IsVoid) return null;
return this;
}
/// <include file='doc\AnyReturnReader.uex' path='docs/doc[@for="AnyReturnReader.Read"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override object Read(WebResponse response, Stream responseStream) {
// caller needs to call close on the stream
return responseStream;
}
}
}

View File

@ -0,0 +1,111 @@
//------------------------------------------------------------------------------
// <copyright file="BufferedResponseStream.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System;
using System.IO;
using System.Web.Services;
internal class BufferedResponseStream : Stream {
Stream outputStream;
byte[] buffer;
int position;
bool flushEnabled = true;
internal BufferedResponseStream(Stream outputStream, int buffersize) {
buffer = new byte[buffersize];
this.outputStream = outputStream;
}
public override bool CanRead { get { return false; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } }
public override long Length { get { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotSeek)); } }
public override long Position {
get { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotSeek)); }
set { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotSeek)); }
}
protected override void Dispose(bool disposing) {
try {
if (disposing)
outputStream.Close();
}
finally {
base.Dispose(disposing);
}
}
internal bool FlushEnabled {
set { flushEnabled = value; }
}
public override void Flush() {
if (!flushEnabled)
return;
FlushWrite();
}
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, Object state) {
throw new NotSupportedException(Res.GetString(Res.StreamDoesNotRead));
}
public override int EndRead(IAsyncResult asyncResult) { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotRead)); }
public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotSeek)); }
public override void SetLength(long value) { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotSeek)); }
public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotRead)); }
public override int ReadByte() { throw new NotSupportedException(Res.GetString(Res.StreamDoesNotRead)); }
public override void Write(byte[] array, int offset, int count) {
if (position > 0) {
int numBytes = buffer.Length - position; // space left in buffer
if (numBytes > 0) {
if (numBytes > count)
numBytes = count;
Array.Copy(array, offset, buffer, position, numBytes);
position += numBytes;
if (count == numBytes) return;
offset += numBytes;
count -= numBytes;
}
FlushWrite();
}
// Skip buffer if we have more bytes then will fit in the buffer.
if (count >= buffer.Length) {
outputStream.Write(array, offset, count);
return;
}
// Copy remaining bytes into buffer, to write at a later date.
Array.Copy(array, offset, buffer, position, count);
position = count;
}
private void FlushWrite() {
if (position > 0) {
outputStream.Write(buffer, 0, position);
position = 0;
}
outputStream.Flush();
}
public override void WriteByte(byte value) {
if (position == buffer.Length)
FlushWrite();
buffer[position++] = value;
}
}
}

View File

@ -0,0 +1,362 @@
//------------------------------------------------------------------------------
// <copyright file="DiscoveryServerProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Web.Services.Description;
using System.Web.Services.Discovery;
using System.Web.UI;
using System.Text;
using System.Diagnostics;
using System.Net;
using System.Web.Services.Configuration;
using System.Globalization;
using System.Collections.Generic;
internal class DiscoveryServerType : ServerType {
ServiceDescription description;
LogicalMethodInfo methodInfo;
Hashtable schemaTable = new Hashtable();
Hashtable wsdlTable = new Hashtable();
DiscoveryDocument discoDoc;
public List<Action<Uri>> UriFixups { get; private set; }
void AddUriFixup(Action<Uri> fixup)
{
if (this.UriFixups != null)
{
this.UriFixups.Add(fixup);
}
}
// See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic.
internal DiscoveryServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey)
: base(typeof(DiscoveryServerProtocol))
{
if (excludeSchemeHostPortFromCachingKey)
{
this.UriFixups = new List<Action<Uri>>();
}
//
// parse the uri from a string into a Uri object
//
Uri uriObject = new Uri(uri, true);
//
// and get rid of the query string if there's one
//
uri = uriObject.GetLeftPart(UriPartial.Path);
methodInfo = new LogicalMethodInfo(typeof(DiscoveryServerProtocol).GetMethod("Discover", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups);
reflector.Reflect(type, uri);
XmlSchemas schemas = reflector.Schemas;
this.description = reflector.ServiceDescription;
// We need to force initialization of ServiceDescription's XmlSerializer since we
// won't necessarily have the permissions to do it when we actually need it
XmlSerializer serializer = ServiceDescription.Serializer;
// add imports to the external schemas
AddSchemaImports(schemas, uri, reflector.ServiceDescriptions);
// add imports to the other service descriptions
for (int i = 1; i < reflector.ServiceDescriptions.Count; i++) {
ServiceDescription description = reflector.ServiceDescriptions[i];
Import import = new Import();
import.Namespace = description.TargetNamespace;
//
string id = "wsdl" + i.ToString(CultureInfo.InvariantCulture);
import.Location = uri + "?wsdl=" + id;
this.AddUriFixup(delegate(Uri current)
{
import.Location = CombineUris(current, import.Location);
});
reflector.ServiceDescription.Imports.Add(import);
wsdlTable.Add(id, description);
}
discoDoc = new DiscoveryDocument();
ContractReference contractReference = new ContractReference(uri + "?wsdl", uri);
this.AddUriFixup(delegate(Uri current)
{
contractReference.Ref = CombineUris(current, contractReference.Ref);
contractReference.DocRef = CombineUris(current, contractReference.DocRef);
});
discoDoc.References.Add(contractReference);
foreach (Service service in reflector.ServiceDescription.Services) {
foreach (Port port in service.Ports) {
SoapAddressBinding soapAddress = (SoapAddressBinding)port.Extensions.Find(typeof(SoapAddressBinding));
if (soapAddress != null) {
System.Web.Services.Discovery.SoapBinding binding = new System.Web.Services.Discovery.SoapBinding();
binding.Binding = port.Binding;
binding.Address = soapAddress.Location;
this.AddUriFixup(delegate(Uri current)
{
binding.Address = CombineUris(current, binding.Address);
});
discoDoc.References.Add(binding);
}
}
}
}
internal void AddExternal(XmlSchema schema, string ns, string location) {
if (schema == null)
return;
if (schema.TargetNamespace == ns) {
XmlSchemaInclude include = new XmlSchemaInclude();
include.SchemaLocation = location;
this.AddUriFixup(delegate(Uri current)
{
include.SchemaLocation = CombineUris(current, include.SchemaLocation);
});
schema.Includes.Add(include);
}
else {
XmlSchemaImport import = new XmlSchemaImport();
import.SchemaLocation = location;
this.AddUriFixup(delegate(Uri current)
{
import.SchemaLocation = CombineUris(current, import.SchemaLocation);
});
import.Namespace = ns;
schema.Includes.Add(import);
}
}
void AddSchemaImports(XmlSchemas schemas, string uri, ServiceDescriptionCollection descriptions) {
int id = 0;
foreach (XmlSchema schema in schemas) {
if (schema == null)
continue;
//
if (schema.Id == null || schema.Id.Length == 0)
schema.Id = "schema" + (++id).ToString(CultureInfo.InvariantCulture);
string location = uri + "?schema=" + schema.Id;
foreach (ServiceDescription description in descriptions) {
if (description.Types.Schemas.Count == 0) {
XmlSchema top = new XmlSchema();
top.TargetNamespace = description.TargetNamespace;
schema.ElementFormDefault = XmlSchemaForm.Qualified;
AddExternal(top, schema.TargetNamespace, location);
description.Types.Schemas.Add(top);
}
else {
AddExternal(description.Types.Schemas[0], schema.TargetNamespace, location);
}
}
//schema.SchemaLocation = location;
schemaTable.Add(schema.Id, schema);
}
}
internal XmlSchema GetSchema(string id) {
return (XmlSchema)schemaTable[id];
}
internal ServiceDescription GetServiceDescription(string id) {
return (ServiceDescription)wsdlTable[id];
}
internal ServiceDescription Description {
get { return description; }
}
internal LogicalMethodInfo MethodInfo {
get { return methodInfo; }
}
internal DiscoveryDocument Disco {
get {
return discoDoc;
}
}
// Creates a new Uri by combining scheme/host/port from the first param and the absolute path and Query from the second
internal static string CombineUris(Uri schemeHostPort, string absolutePathAndQuery)
{
return string.Format(CultureInfo.InvariantCulture, "{0}://{1}{2}",
schemeHostPort.Scheme,
schemeHostPort.Authority,
new Uri(absolutePathAndQuery).PathAndQuery);
}
}
internal class DiscoveryServerProtocolFactory : ServerProtocolFactory {
protected override ServerProtocol CreateIfRequestCompatible(HttpRequest request) {
if (request.PathInfo.Length > 0)
return null;
if (request.HttpMethod != "GET")
// MethodNotAllowed = 405,
return new UnsupportedRequestProtocol(405);
string queryString = request.QueryString[null];
if (queryString == null) queryString = "";
if (request.QueryString["schema"] == null &&
request.QueryString["wsdl"] == null &&
string.Compare(queryString, "wsdl", StringComparison.OrdinalIgnoreCase) != 0 &&
string.Compare(queryString, "disco", StringComparison.OrdinalIgnoreCase) != 0)
return null;
return new DiscoveryServerProtocol();
}
}
internal sealed class DiscoveryServerProtocol : ServerProtocol {
DiscoveryServerType serverType;
object syncRoot = new object();
internal override bool Initialize() {
//
// see if we already cached a DiscoveryServerType
//
if (null == (serverType = (DiscoveryServerType)GetFromCache(typeof(DiscoveryServerProtocol), Type))
&& null == (serverType = (DiscoveryServerType)GetFromCache(typeof(DiscoveryServerProtocol), Type, true))) {
lock (InternalSyncObject) {
if (null == (serverType = (DiscoveryServerType)GetFromCache(typeof(DiscoveryServerProtocol), Type))
&& null == (serverType = (DiscoveryServerType)GetFromCache(typeof(DiscoveryServerProtocol), Type, true)))
{
//
// if not create a new DiscoveryServerType and cache it
//
bool excludeSchemeHostPortFromCachingKey = this.IsCacheUnderPressure(typeof(DiscoveryServerProtocol), Type);
string escapedUri = RuntimeUtils.EscapeUri(Request.Url);
serverType = new DiscoveryServerType(Type, escapedUri, excludeSchemeHostPortFromCachingKey);
AddToCache(typeof(DiscoveryServerProtocol), Type, serverType, excludeSchemeHostPortFromCachingKey);
}
}
}
return true;
}
internal override ServerType ServerType {
get { return serverType; }
}
internal override bool IsOneWay {
get { return false; }
}
internal override LogicalMethodInfo MethodInfo {
get { return serverType.MethodInfo; }
}
internal override object[] ReadParameters() {
return new object[0];
}
internal override void WriteReturns(object[] returnValues, Stream outputStream) {
string id = Request.QueryString["schema"];
Encoding encoding = new UTF8Encoding(false);
if (id != null) {
XmlSchema schema = serverType.GetSchema(id);
if (schema == null) throw new InvalidOperationException(Res.GetString(Res.WebSchemaNotFound));
Response.ContentType = ContentType.Compose("text/xml", encoding);
schema.Write(new StreamWriter(outputStream, encoding));
return;
}
id = Request.QueryString["wsdl"];
if (id != null) {
ServiceDescription description = serverType.GetServiceDescription(id);
if (description == null) throw new InvalidOperationException(Res.GetString(Res.ServiceDescriptionWasNotFound0));
Response.ContentType = ContentType.Compose("text/xml", encoding);
if (this.serverType.UriFixups == null)
{
description.Write(new StreamWriter(outputStream, encoding));
}
else
{
lock (this.syncRoot)
{
this.RunUriFixups();
description.Write(new StreamWriter(outputStream, encoding));
}
}
return;
}
string queryString = Request.QueryString[null];
if (queryString != null && string.Compare(queryString, "wsdl", StringComparison.OrdinalIgnoreCase) == 0) {
Response.ContentType = ContentType.Compose("text/xml", encoding);
if (this.serverType.UriFixups == null)
{
serverType.Description.Write(new StreamWriter(outputStream, encoding));
}
else
{
lock (this.syncRoot)
{
this.RunUriFixups();
serverType.Description.Write(new StreamWriter(outputStream, encoding));
}
}
return;
}
if (queryString != null && string.Compare(queryString, "disco", StringComparison.OrdinalIgnoreCase) == 0) {
Response.ContentType = ContentType.Compose("text/xml", encoding);
if (this.serverType.UriFixups == null)
{
serverType.Disco.Write(new StreamWriter(outputStream, encoding));
}
else
{
lock (this.syncRoot)
{
this.RunUriFixups();
serverType.Disco.Write(new StreamWriter(outputStream, encoding));
}
}
return;
}
throw new InvalidOperationException(Res.GetString(Res.internalError0));
}
internal override bool WriteException(Exception e, Stream outputStream) {
Response.Clear();
Response.ClearHeaders();
Response.ContentType = ContentType.Compose("text/plain", Encoding.UTF8);
Response.StatusCode = (int) HttpStatusCode.InternalServerError;
Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
StreamWriter writer = new StreamWriter(outputStream, new UTF8Encoding(false));
writer.WriteLine(GenerateFaultString(e, true));
writer.Flush();
return true;
}
internal void Discover() {
// This is the "server method" that is called for this protocol
}
void RunUriFixups()
{
foreach (Action<Uri> fixup in this.serverType.UriFixups)
{
fixup(this.Context.Request.Url);
}
}
}
}

View File

@ -0,0 +1,222 @@
//------------------------------------------------------------------------------
// <copyright file="DocumentationServerProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Web.Services.Discovery;
using System.Web.UI;
using System.Diagnostics;
using System.Web.Services.Configuration;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Text;
using System.Net;
using System.Web.Services.Description;
using System.Threading;
using System.Web.Services.Diagnostics;
using System.Security.Permissions;
using System.Collections.Generic;
internal class DocumentationServerType : ServerType {
ServiceDescriptionCollection serviceDescriptions, serviceDescriptionsWithPost;
XmlSchemas schemas, schemasWithPost;
LogicalMethodInfo methodInfo;
public List<Action<Uri>> UriFixups { get; private set; }
void AddUriFixup(Action<Uri> fixup)
{
if (this.UriFixups != null)
{
this.UriFixups.Add(fixup);
}
}
// See comment on the ServerProtocol.IsCacheUnderPressure method for explanation of the excludeSchemeHostPortFromCachingKey logic.
internal DocumentationServerType(Type type, string uri, bool excludeSchemeHostPortFromCachingKey)
: base(typeof(DocumentationServerProtocol))
{
if (excludeSchemeHostPortFromCachingKey)
{
this.UriFixups = new List<Action<Uri>>();
}
//
// parse the uri from a string into a URI object
//
Uri uriObject = new Uri(uri, true);
//
// and get rid of the query string if there's one
//
uri = uriObject.GetLeftPart(UriPartial.Path);
methodInfo = new LogicalMethodInfo(typeof(DocumentationServerProtocol).GetMethod("Documentation", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(this.UriFixups);
reflector.Reflect(type, uri);
schemas = reflector.Schemas;
serviceDescriptions = reflector.ServiceDescriptions;
schemasWithPost = reflector.SchemasWithPost;
serviceDescriptionsWithPost = reflector.ServiceDescriptionsWithPost;
}
internal LogicalMethodInfo MethodInfo {
get { return methodInfo; }
}
internal XmlSchemas Schemas {
get { return schemas; }
}
internal ServiceDescriptionCollection ServiceDescriptions {
get { return serviceDescriptions; }
}
internal ServiceDescriptionCollection ServiceDescriptionsWithPost {
get { return serviceDescriptionsWithPost; }
}
internal XmlSchemas SchemasWithPost {
get { return schemasWithPost; }
}
}
internal class DocumentationServerProtocolFactory : ServerProtocolFactory {
protected override ServerProtocol CreateIfRequestCompatible(HttpRequest request) {
if (request.PathInfo.Length > 0)
return null;
if (request.HttpMethod != "GET")
// MethodNotAllowed = 405,
return new UnsupportedRequestProtocol(405);
return new DocumentationServerProtocol();
}
}
internal sealed class DocumentationServerProtocol : ServerProtocol {
DocumentationServerType serverType;
IHttpHandler handler = null;
object syncRoot = new object();
private const int MAX_PATH_SIZE = 1024;
internal override bool Initialize() {
//
// see if we already cached a DocumentationServerType
//
if (null == (serverType = (DocumentationServerType)GetFromCache(typeof(DocumentationServerProtocol), Type))
&& null == (serverType = (DocumentationServerType)GetFromCache(typeof(DocumentationServerProtocol), Type, true))) {
lock (InternalSyncObject) {
if (null == (serverType = (DocumentationServerType)GetFromCache(typeof(DocumentationServerProtocol), Type))
&& null == (serverType = (DocumentationServerType)GetFromCache(typeof(DocumentationServerProtocol), Type, true)))
{
//
// if not create a new DocumentationServerType and cache it
//
//
bool excludeSchemeHostPortFromCachingKey = this.IsCacheUnderPressure(typeof(DocumentationServerProtocol), Type);
string escapedUri = RuntimeUtils.EscapeUri(Request.Url);
serverType = new DocumentationServerType(Type, escapedUri, excludeSchemeHostPortFromCachingKey);
AddToCache(typeof(DocumentationServerProtocol), Type, serverType, excludeSchemeHostPortFromCachingKey);
}
}
}
WebServicesSection config = WebServicesSection.Current;
if (config.WsdlHelpGenerator.Href != null && config.WsdlHelpGenerator.Href.Length > 0)
{
TraceMethod caller = Tracing.On ? new TraceMethod(this, "Initialize") : null;
if (Tracing.On) Tracing.Enter("ASP.NET", caller, new TraceMethod(typeof(PageParser), "GetCompiledPageInstance", config.WsdlHelpGenerator.HelpGeneratorVirtualPath, config.WsdlHelpGenerator.HelpGeneratorPath, Context));
handler = GetCompiledPageInstance(config.WsdlHelpGenerator.HelpGeneratorVirtualPath,
config.WsdlHelpGenerator.HelpGeneratorPath,
Context);
if (Tracing.On) Tracing.Exit("ASP.NET", caller);
}
return true;
}
// Asserts SecurityPermission and FileIOPermission.
// Justification: Security Permission is demanded by PageParser.GetCompiledPageInstance() method.
// It is used to initialize the IHttpHandler field of the DocumentationServerProtocol object.
// FileIOPermission is required to access the inputFile passed in as a parameter.
// It is used only to map the virtual path to the physical file path. The FileIOPermission is not used to access any file other than the one passed in.
[SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
[FileIOPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
private IHttpHandler GetCompiledPageInstance(string virtualPath, string inputFile, HttpContext context)
{
return PageParser.GetCompiledPageInstance(virtualPath, inputFile, context);
}
internal override ServerType ServerType {
get { return serverType; }
}
internal override bool IsOneWay {
get { return false; }
}
internal override LogicalMethodInfo MethodInfo {
get { return serverType.MethodInfo; }
}
internal override object[] ReadParameters() {
return new object[0];
}
internal override void WriteReturns(object[] returnValues, Stream outputStream) {
try {
if (handler != null) {
Context.Items.Add("wsdls", serverType.ServiceDescriptions);
Context.Items.Add("schemas", serverType.Schemas);
// conditionally add post-enabled wsdls and schemas to support localhost-only post
if (Context.Request.Url.IsLoopback || Context.Request.IsLocal) {
Context.Items.Add("wsdlsWithPost", serverType.ServiceDescriptionsWithPost);
Context.Items.Add("schemasWithPost", serverType.SchemasWithPost);
}
Context.Items.Add("conformanceWarnings", WebServicesSection.Current.EnabledConformanceWarnings);
Response.ContentType = "text/html";
if (this.serverType.UriFixups == null)
{
handler.ProcessRequest(Context);
}
else
{
lock (this.syncRoot)
{
this.RunUriFixups();
handler.ProcessRequest(Context);
}
}
}
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
throw new InvalidOperationException(Res.GetString(Res.HelpGeneratorInternalError), e);
}
}
internal override bool WriteException(Exception e, Stream outputStream) {
return false;
}
internal void Documentation() {
// This is the "server method" that is called for this protocol
}
void RunUriFixups()
{
foreach (Action<Uri> fixup in this.serverType.UriFixups)
{
fixup(this.Context.Request.Url);
}
}
}
}

View File

@ -0,0 +1,32 @@
//------------------------------------------------------------------------------
// <copyright file="HtmlFormParameterReader.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.IO;
using System;
using System.Xml.Serialization;
using System.Reflection;
using System.Collections;
using System.Web.Services;
/// <include file='doc\HtmlFormParameterReader.uex' path='docs/doc[@for="HtmlFormParameterReader"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class HtmlFormParameterReader : ValueCollectionParameterReader {
internal const string MimeType = "application/x-www-form-urlencoded";
/// <include file='doc\HtmlFormParameterReader.uex' path='docs/doc[@for="HtmlFormParameterReader.Read"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override object[] Read(HttpRequest request) {
if (!ContentType.MatchesBase(request.ContentType, MimeType)) return null;
return Read(request.Form);
}
}
}

View File

@ -0,0 +1,49 @@
//------------------------------------------------------------------------------
// <copyright file="HtmlFormParameterWriter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.IO;
using System;
using System.Text;
using System.Xml.Serialization;
using System.Reflection;
using System.Collections;
using System.Web.Services;
using System.Net;
/// <include file='doc\HtmlFormParameterWriter.uex' path='docs/doc[@for="HtmlFormParameterWriter"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class HtmlFormParameterWriter : UrlEncodedParameterWriter {
/// <include file='doc\HtmlFormParameterWriter.uex' path='docs/doc[@for="HtmlFormParameterWriter.UsesWriteRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override bool UsesWriteRequest { get { return true; } }
/// <include file='doc\HtmlFormParameterWriter.uex' path='docs/doc[@for="HtmlFormParameterWriter.InitializeRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override void InitializeRequest(WebRequest request, object[] values) {
request.ContentType = ContentType.Compose(HtmlFormParameterReader.MimeType, RequestEncoding);
}
/// <include file='doc\HtmlFormParameterWriter.uex' path='docs/doc[@for="HtmlFormParameterWriter.WriteRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override void WriteRequest(Stream requestStream, object[] values) {
if (values.Length == 0) return;
// just use ASCII encoding since we're url-escaping everything...
TextWriter writer = new StreamWriter(requestStream, new ASCIIEncoding());
Encode(writer, values);
writer.Flush();
}
}
}

View File

@ -0,0 +1,348 @@
//------------------------------------------------------------------------------
// <copyright file="HttpClientProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
using System.Net;
using System.Text;
using System.Threading;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Web.Services.Diagnostics;
internal class HttpClientMethod {
internal Type readerType;
internal object readerInitializer;
internal Type writerType;
internal object writerInitializer;
internal LogicalMethodInfo methodInfo;
}
internal class HttpClientType {
Hashtable methods = new Hashtable();
internal HttpClientType(Type type) {
LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync);
Hashtable formatterTypes = new Hashtable();
for (int i = 0; i < methodInfos.Length; i++) {
LogicalMethodInfo methodInfo = methodInfos[i];
try {
object[] attributes = methodInfo.GetCustomAttributes(typeof(HttpMethodAttribute));
if (attributes.Length == 0) continue;
HttpMethodAttribute attribute = (HttpMethodAttribute)attributes[0];
HttpClientMethod method = new HttpClientMethod();
method.readerType = attribute.ReturnFormatter;
method.writerType = attribute.ParameterFormatter;
method.methodInfo = methodInfo;
AddFormatter(formatterTypes, method.readerType, method);
AddFormatter(formatterTypes, method.writerType, method);
methods.Add(methodInfo.Name, method);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
throw new InvalidOperationException(Res.GetString(Res.WebReflectionError, methodInfo.DeclaringType.FullName, methodInfo.Name), e);
}
}
foreach (Type t in formatterTypes.Keys) {
ArrayList list = (ArrayList)formatterTypes[t];
LogicalMethodInfo[] m = new LogicalMethodInfo[list.Count];
for (int j = 0; j < list.Count; j++)
m[j] = ((HttpClientMethod)list[j]).methodInfo;
object[] initializers = MimeFormatter.GetInitializers(t, m);
bool isWriter = typeof(MimeParameterWriter).IsAssignableFrom(t);
for (int j = 0; j < list.Count; j++) {
if (isWriter) {
((HttpClientMethod)list[j]).writerInitializer = initializers[j];
}
else {
((HttpClientMethod)list[j]).readerInitializer = initializers[j];
}
}
}
}
static void AddFormatter(Hashtable formatterTypes, Type formatterType, HttpClientMethod method) {
if (formatterType == null) return;
ArrayList list = (ArrayList)formatterTypes[formatterType];
if (list == null) {
list = new ArrayList();
formatterTypes.Add(formatterType, list);
}
list.Add(method);
}
internal HttpClientMethod GetMethod(string name) {
return (HttpClientMethod)methods[name];
}
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol"]/*' />
/// <devdoc>
/// <para>
/// Specifies
/// most of the implementation for communicating with an HTTP web service over HTTP.
/// </para>
/// </devdoc>
[ComVisible(true)]
public abstract class HttpSimpleClientProtocol : HttpWebClientProtocol {
HttpClientType clientType;
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.HttpSimpleClientProtocol"]/*' />
/// <devdoc>
/// <para>
/// Initializes a new instance of the <see cref='System.Web.Services.Protocols.HttpSimpleClientProtocol'/> class.
/// </para>
/// </devdoc>
protected HttpSimpleClientProtocol()
: base() {
Type type = this.GetType();
clientType = (HttpClientType)GetFromCache(type);
if (clientType == null) {
lock (InternalSyncObject) {
clientType = (HttpClientType)GetFromCache(type);
if (clientType == null) {
clientType = new HttpClientType(type);
AddToCache(type, clientType);
}
}
}
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.Invoke"]/*' />
/// <devdoc>
/// <para>
/// Invokes a method of a HTTP web service.
/// </para>
/// </devdoc>
protected object Invoke(string methodName, string requestUrl, object[] parameters) {
WebResponse response = null;
HttpClientMethod method = GetClientMethod(methodName);
MimeParameterWriter paramWriter = GetParameterWriter(method);
Uri requestUri = new Uri(requestUrl);
if (paramWriter != null) {
paramWriter.RequestEncoding = RequestEncoding;
requestUrl = paramWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
requestUri = new Uri(requestUrl, true);
}
WebRequest request = null;
try {
request = GetWebRequest(requestUri);
NotifyClientCallOut(request);
PendingSyncRequest = request;
if (paramWriter != null) {
paramWriter.InitializeRequest(request, parameters);
//
if (paramWriter.UsesWriteRequest) {
if (parameters.Length == 0)
request.ContentLength = 0;
else {
Stream requestStream = null;
try {
requestStream = request.GetRequestStream();
paramWriter.WriteRequest(requestStream, parameters);
}
finally {
if (requestStream != null) requestStream.Close();
}
}
}
}
response = GetWebResponse(request);
Stream responseStream = null;
if (response.ContentLength != 0)
responseStream = response.GetResponseStream();
return ReadResponse(method, response, responseStream);
}
finally {
if (request == PendingSyncRequest)
PendingSyncRequest = null;
}
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.BeginInvoke"]/*' />
/// <devdoc>
/// <para>
/// Starts an asynchronous invocation of a method of a HTTP web service.
/// </para>
/// </devdoc>
protected IAsyncResult BeginInvoke(string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState) {
HttpClientMethod method = GetClientMethod(methodName);
MimeParameterWriter paramWriter = GetParameterWriter(method);
Uri requestUri = new Uri(requestUrl);
if (paramWriter != null) {
paramWriter.RequestEncoding = RequestEncoding;
requestUrl = paramWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
requestUri = new Uri(requestUrl, true);
}
InvokeAsyncState invokeState = new InvokeAsyncState(method, paramWriter, parameters);
WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, invokeState, null, callback, asyncState);
return BeginSend(requestUri, asyncResult, paramWriter.UsesWriteRequest);
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.InitializeAsyncRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
internal override void InitializeAsyncRequest(WebRequest request, object internalAsyncState) {
InvokeAsyncState invokeState = (InvokeAsyncState)internalAsyncState;
if (invokeState.ParamWriter.UsesWriteRequest && invokeState.Parameters.Length == 0)
request.ContentLength = 0;
}
internal override void AsyncBufferedSerialize(WebRequest request, Stream requestStream, object internalAsyncState) {
InvokeAsyncState invokeState = (InvokeAsyncState)internalAsyncState;
if (invokeState.ParamWriter != null) {
invokeState.ParamWriter.InitializeRequest(request, invokeState.Parameters);
if (invokeState.ParamWriter.UsesWriteRequest && invokeState.Parameters.Length > 0)
invokeState.ParamWriter.WriteRequest(requestStream, invokeState.Parameters);
}
}
class InvokeAsyncState {
internal object[] Parameters;
internal MimeParameterWriter ParamWriter;
internal HttpClientMethod Method;
internal InvokeAsyncState(HttpClientMethod method, MimeParameterWriter paramWriter, object[] parameters) {
this.Method = method;
this.ParamWriter = paramWriter;
this.Parameters = parameters;
}
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.EndInvoke"]/*' />
/// <devdoc>
/// <para>
/// Ends an asynchronous invocation of a method of a HTTP web service.
/// </para>
/// </devdoc>
protected object EndInvoke(IAsyncResult asyncResult) {
object o = null;
Stream responseStream = null;
WebResponse response = EndSend(asyncResult, ref o, ref responseStream);
InvokeAsyncState invokeState = (InvokeAsyncState) o;
return ReadResponse(invokeState.Method, response, responseStream);
}
private void InvokeAsyncCallback(IAsyncResult result) {
object parameter = null;
Exception exception = null;
WebClientAsyncResult asyncResult = (WebClientAsyncResult)result;
if (asyncResult.Request != null) {
try {
object o = null;
Stream responseStream = null;
WebResponse response = EndSend(asyncResult, ref o, ref responseStream);
InvokeAsyncState invokeState = (InvokeAsyncState) o;
parameter = ReadResponse(invokeState.Method, response, responseStream);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
throw;
exception = e;
if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsyncCallback", e);
}
}
AsyncOperation asyncOp = (AsyncOperation)result.AsyncState;
UserToken token = (UserToken)asyncOp.UserSuppliedState;
OperationCompleted(token.UserState, new object[] { parameter }, exception, false);
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.InvokeAsync"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
protected void InvokeAsync(string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback) {
InvokeAsync(methodName, requestUrl, parameters, callback, null);
}
/// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.InvokeAsync1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
protected void InvokeAsync(string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback, object userState) {
if (userState == null)
userState = NullToken;
AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, null, null, new AsyncCallback(InvokeAsyncCallback), asyncOp);
try {
AsyncInvokes.Add(userState, asyncResult);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
throw;
if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", e);
Exception exception = new ArgumentException(Res.GetString(Res.AsyncDuplicateUserState), e);
InvokeCompletedEventArgs eventArgs = new InvokeCompletedEventArgs(new object[] { null }, exception, false, userState);
asyncOp.PostOperationCompleted(callback, eventArgs);
return;
}
try {
HttpClientMethod method = GetClientMethod(methodName);
MimeParameterWriter paramWriter = GetParameterWriter(method);
Uri requestUri = new Uri(requestUrl);
if (paramWriter != null) {
paramWriter.RequestEncoding = RequestEncoding;
requestUrl = paramWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
requestUri = new Uri(requestUrl, true);
}
asyncResult.InternalAsyncState = new InvokeAsyncState(method, paramWriter, parameters);
BeginSend(requestUri, asyncResult, paramWriter.UsesWriteRequest);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
throw;
if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", e);
OperationCompleted(userState, new object[] { null }, e, false);
}
}
MimeParameterWriter GetParameterWriter(HttpClientMethod method) {
if (method.writerType == null)
return null;
return (MimeParameterWriter)MimeFormatter.CreateInstance(method.writerType, method.writerInitializer);
}
HttpClientMethod GetClientMethod(string methodName) {
HttpClientMethod method = clientType.GetMethod(methodName);
if (method == null) throw new ArgumentException(Res.GetString(Res.WebInvalidMethodName, methodName), "methodName");
return method;
}
object ReadResponse(HttpClientMethod method, WebResponse response, Stream responseStream) {
HttpWebResponse httpResponse = response as HttpWebResponse;
if (httpResponse != null && (int)httpResponse.StatusCode >= 300)
throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null,
WebExceptionStatus.ProtocolError, httpResponse);
if (method.readerType == null)
return null;
//
if (responseStream != null) {
MimeReturnReader reader = (MimeReturnReader)MimeFormatter.CreateInstance(method.readerType, method.readerInitializer);
return reader.Read(response, responseStream);
}
else
return null;
}
}
}

View File

@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <copyright file="HttpGetClientProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.Net;
using System.IO;
/// <include file='doc\HttpGetClientProtocol.uex' path='docs/doc[@for="HttpGetClientProtocol"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class HttpGetClientProtocol : HttpSimpleClientProtocol {
/// <include file='doc\HttpGetClientProtocol.uex' path='docs/doc[@for="HttpGetClientProtocol.HttpGetClientProtocol"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public HttpGetClientProtocol()
: base() {
}
/// <include file='doc\HttpGetClientProtocol.uex' path='docs/doc[@for="HttpGetClientProtocol.GetWebRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
protected override WebRequest GetWebRequest(Uri uri) {
WebRequest request = base.GetWebRequest(uri);
request.Method = "GET";
return request;
}
}
}

View File

@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// <copyright file="HttpGetServerProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
internal class HttpGetServerProtocolFactory : ServerProtocolFactory {
protected override ServerProtocol CreateIfRequestCompatible(HttpRequest request) {
if (request.PathInfo.Length < 2)
return null;
if (request.HttpMethod != "GET")
// MethodNotAllowed = 405,
return new UnsupportedRequestProtocol(405);
return new HttpGetServerProtocol();
}
}
internal class HttpGetServerProtocol : HttpServerProtocol {
internal HttpGetServerProtocol() : base(false) { }
}
}

View File

@ -0,0 +1,55 @@
//------------------------------------------------------------------------------
// <copyright file="HttpMethodAttribute.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System;
/// <include file='doc\HttpMethodAttribute.uex' path='docs/doc[@for="HttpMethodAttribute"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[AttributeUsage(AttributeTargets.Method)]
public sealed class HttpMethodAttribute : System.Attribute {
Type returnFormatter;
Type parameterFormatter;
/// <include file='doc\HttpMethodAttribute.uex' path='docs/doc[@for="HttpMethodAttribute.HttpMethodAttribute"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public HttpMethodAttribute() {
returnFormatter = null;
parameterFormatter = null;
}
/// <include file='doc\HttpMethodAttribute.uex' path='docs/doc[@for="HttpMethodAttribute.HttpMethodAttribute1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public HttpMethodAttribute(Type returnFormatter, Type parameterFormatter) {
this.returnFormatter = returnFormatter;
this.parameterFormatter = parameterFormatter;
}
/// <include file='doc\HttpMethodAttribute.uex' path='docs/doc[@for="HttpMethodAttribute.ReturnFormatter"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Type ReturnFormatter {
get { return returnFormatter; }
set { returnFormatter = value; }
}
/// <include file='doc\HttpMethodAttribute.uex' path='docs/doc[@for="HttpMethodAttribute.ParameterFormatter"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public Type ParameterFormatter {
get { return parameterFormatter; }
set { parameterFormatter = value; }
}
}
}

View File

@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <copyright file="HttpPostClientProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.Net;
using System.IO;
/// <include file='doc\HttpPostClientProtocol.uex' path='docs/doc[@for="HttpPostClientProtocol"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class HttpPostClientProtocol : HttpSimpleClientProtocol {
/// <include file='doc\HttpPostClientProtocol.uex' path='docs/doc[@for="HttpPostClientProtocol.HttpPostClientProtocol"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public HttpPostClientProtocol()
: base() {
}
/// <include file='doc\HttpPostClientProtocol.uex' path='docs/doc[@for="HttpPostClientProtocol.GetWebRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
protected override WebRequest GetWebRequest(Uri uri) {
WebRequest request = base.GetWebRequest(uri);
request.Method = "POST";
return request;
}
}
}

View File

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <copyright file="HttpPostServerProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.Net;
internal class HttpPostLocalhostServerProtocolFactory : ServerProtocolFactory {
protected override ServerProtocol CreateIfRequestCompatible(HttpRequest request) {
if (request.PathInfo.Length < 2)
return null;
if (request.HttpMethod != "POST")
// MethodNotAllowed = 405,
return new UnsupportedRequestProtocol(405);
bool isLocal = request.Url.IsLoopback || request.IsLocal;
if (!isLocal)
return null;
return new HttpPostServerProtocol();
}
}
}

View File

@ -0,0 +1,24 @@
//------------------------------------------------------------------------------
// <copyright file="HttpPostServerProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
internal class HttpPostServerProtocolFactory : ServerProtocolFactory {
protected override ServerProtocol CreateIfRequestCompatible(HttpRequest request) {
if (request.PathInfo.Length < 2)
return null;
if (request.HttpMethod != "POST")
// MethodNotAllowed = 405,
return new UnsupportedRequestProtocol(405);
return new HttpPostServerProtocol();
}
}
internal class HttpPostServerProtocol : HttpServerProtocol {
internal HttpPostServerProtocol() : base(true) { }
}
}

View File

@ -0,0 +1,255 @@
//------------------------------------------------------------------------------
// <copyright file="HttpServerProtocol.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System;
using System.Diagnostics;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml.Serialization;
using System.Web.Services.Description;
using System.Web.Services.Configuration;
using System.Net;
using System.Globalization;
internal class HttpServerType : ServerType {
Hashtable methods = new Hashtable();
internal HttpServerType(Type type) : base(type) {
WebServicesSection config = WebServicesSection.Current;
Type[] returnWriterTypes = config.ReturnWriterTypes;
Type[] parameterReaderTypes = config.ParameterReaderTypes;
LogicalMethodInfo[] methodInfos = WebMethodReflector.GetMethods(type);
HttpServerMethod[] methods = new HttpServerMethod[methodInfos.Length];
object[] initializersByType = new object[returnWriterTypes.Length];
for (int i = 0; i < initializersByType.Length; i++) {
initializersByType[i] = MimeFormatter.GetInitializers(returnWriterTypes[i], methodInfos);
}
for (int i = 0; i < methodInfos.Length; i++) {
LogicalMethodInfo methodInfo = methodInfos[i];
HttpServerMethod method = null;
if (methodInfo.ReturnType == typeof(void)) {
method = new HttpServerMethod();
}
else {
for (int j = 0; j < returnWriterTypes.Length; j++) {
object[] initializers = (object[])initializersByType[j];
if (initializers[i] != null) {
method = new HttpServerMethod();
method.writerInitializer = initializers[i];
method.writerType = returnWriterTypes[j];
break;
}
}
}
if (method != null) {
method.methodInfo = methodInfo;
methods[i] = method;
}
}
initializersByType = new object[parameterReaderTypes.Length];
for (int i = 0; i < initializersByType.Length; i++) {
initializersByType[i] = MimeFormatter.GetInitializers(parameterReaderTypes[i], methodInfos);
}
for (int i = 0; i < methodInfos.Length; i++) {
HttpServerMethod method = methods[i];
if (method == null) continue;
LogicalMethodInfo methodInfo = methodInfos[i];
if (methodInfo.InParameters.Length > 0) {
int count = 0;
for (int j = 0; j < parameterReaderTypes.Length; j++) {
object[] initializers = (object[])initializersByType[j];
if (initializers[i] != null) {
count++;
}
}
if (count == 0) {
methods[i] = null;
}
else {
method.readerTypes = new Type[count];
method.readerInitializers = new object[count];
count = 0;
for (int j = 0; j < parameterReaderTypes.Length; j++) {
object[] initializers = (object[])initializersByType[j];
if (initializers[i] != null) {
method.readerTypes[count] = parameterReaderTypes[j];
method.readerInitializers[count] = initializers[i];
count++;
}
}
}
}
}
for (int i = 0; i < methods.Length; i++) {
HttpServerMethod method = methods[i];
if (method != null) {
WebMethodAttribute methodAttribute = method.methodInfo.MethodAttribute;
method.name = methodAttribute.MessageName;
if (method.name.Length == 0) method.name = method.methodInfo.Name;
this.methods.Add(method.name, method);
}
}
}
internal HttpServerMethod GetMethod(string name) {
return (HttpServerMethod)methods[name];
}
internal HttpServerMethod GetMethodIgnoreCase(string name) {
foreach (DictionaryEntry entry in methods) {
HttpServerMethod method = (HttpServerMethod)entry.Value;
if (String.Compare(method.name, name, StringComparison.OrdinalIgnoreCase) == 0)
return method;
}
return null;
}
}
internal class HttpServerMethod {
internal string name;
internal LogicalMethodInfo methodInfo;
internal Type[] readerTypes;
internal object[] readerInitializers;
internal Type writerType;
internal object writerInitializer;
}
internal abstract class HttpServerProtocol : ServerProtocol {
HttpServerMethod serverMethod;
HttpServerType serverType;
bool hasInputPayload;
protected HttpServerProtocol(bool hasInputPayload) {
this.hasInputPayload = hasInputPayload;
}
internal override bool Initialize() {
// The derived class better check the verb!
string methodName = Request.PathInfo.Substring(1); // Skip leading '/'
if (null == (serverType = (HttpServerType)GetFromCache(typeof(HttpServerProtocol), Type))
&& null == (serverType = (HttpServerType)GetFromCache(typeof(HttpServerProtocol), Type, true)))
{
lock (InternalSyncObject)
{
if (null == (serverType = (HttpServerType)GetFromCache(typeof(HttpServerProtocol), Type))
&& null == (serverType = (HttpServerType)GetFromCache(typeof(HttpServerProtocol), Type, true)))
{
bool excludeSchemeHostPortFromCachingKey = this.IsCacheUnderPressure(typeof(HttpServerProtocol), Type);
serverType = new HttpServerType(Type);
AddToCache(typeof(HttpServerProtocol), Type, serverType, excludeSchemeHostPortFromCachingKey);
}
}
}
serverMethod = serverType.GetMethod(methodName);
if (serverMethod == null) {
serverMethod = serverType.GetMethodIgnoreCase(methodName);
if (serverMethod != null)
throw new ArgumentException(Res.GetString(Res.WebInvalidMethodNameCase, methodName, serverMethod.name), "methodName");
else {
// it's possible that the method name came in as UTF-8 but was mangled by IIS so we try it
// again as UTF8...
string utf8MethodName = Encoding.UTF8.GetString(Encoding.Default.GetBytes(methodName));
serverMethod = serverType.GetMethod(utf8MethodName);
if (serverMethod == null)
throw new InvalidOperationException(Res.GetString(Res.WebInvalidMethodName, methodName));
}
}
return true;
}
internal override bool IsOneWay {
get { return false; }
}
internal override LogicalMethodInfo MethodInfo {
get { return serverMethod.methodInfo; }
}
internal override ServerType ServerType {
get { return serverType; }
}
internal override object[] ReadParameters() {
if (serverMethod.readerTypes == null) return new object[0];
for (int i = 0; i < serverMethod.readerTypes.Length; i++) {
if (!hasInputPayload) {
// only allow URL parameters if doesn't have payload
if (serverMethod.readerTypes[i] != typeof(UrlParameterReader)) continue;
}
else {
// don't allow URL params if has payload
if (serverMethod.readerTypes[i] == typeof(UrlParameterReader)) continue;
}
MimeParameterReader reader = (MimeParameterReader)MimeFormatter.CreateInstance(serverMethod.readerTypes[i],
serverMethod.readerInitializers[i]);
object[] parameters = reader.Read(Request);
if (parameters != null) return parameters;
}
if (!hasInputPayload)
throw new InvalidOperationException(Res.GetString(Res.WebInvalidRequestFormat));
else
throw new InvalidOperationException(Res.GetString(Res.WebInvalidRequestFormatDetails, Request.ContentType));
}
internal override void WriteReturns(object[] returnValues, Stream outputStream) {
if (serverMethod.writerType == null) return;
MimeReturnWriter writer = (MimeReturnWriter)MimeFormatter.CreateInstance(serverMethod.writerType,
serverMethod.writerInitializer);
writer.Write(Response, outputStream, returnValues[0]);
}
internal override bool WriteException(Exception e, Stream outputStream) {
Response.Clear();
Response.ClearHeaders();
Response.ContentType = ContentType.Compose("text/plain", Encoding.UTF8);
SetHttpResponseStatusCode(Response, (int)HttpStatusCode.InternalServerError);
Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
StreamWriter writer = new StreamWriter(outputStream, new UTF8Encoding(false));
if (System.Web.Services.Configuration.WebServicesSection.Current.Diagnostics.SuppressReturningExceptions) {
writer.WriteLine(Res.GetString(Res.WebSuppressedExceptionMessage));
}
else {
writer.WriteLine(GenerateFaultString(e, true));
}
writer.Flush();
return true;
}
internal static bool AreUrlParametersSupported(LogicalMethodInfo methodInfo) {
if (methodInfo.OutParameters.Length > 0) return false;
ParameterInfo[] parameters = methodInfo.InParameters;
for (int i = 0; i < parameters.Length; i++) {
ParameterInfo parameter = parameters[i];
Type parameterType = parameter.ParameterType;
if (parameterType.IsArray) {
if (!ScalarFormatter.IsTypeSupported(parameterType.GetElementType()))
return false;
}
else {
if (!ScalarFormatter.IsTypeSupported(parameterType))
return false;
}
}
return true;
}
}
}

View File

@ -0,0 +1,70 @@
namespace System.Web.Services.Protocols {
using System;
using System.Security.Permissions;
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[AttributeUsage(AttributeTargets.All)]
public sealed class MatchAttribute : System.Attribute {
string pattern;
int group = 1;
int capture = 0;
bool ignoreCase = false;
int repeats = -1;
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute.MatchAttribute"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public MatchAttribute(string pattern) {
this.pattern = pattern;
}
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute.Pattern"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public string Pattern {
get { return pattern == null ? string.Empty : pattern; }
set { pattern = value; }
}
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute.Group"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int Group {
get { return group; }
set { group = value; }
}
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute.Capture"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int Capture {
get { return capture; }
set { capture = value; }
}
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute.IgnoreCase"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool IgnoreCase {
get { return ignoreCase; }
set { ignoreCase = value; }
}
/// <include file='doc\MatchAttribute.uex' path='docs/doc[@for="MatchAttribute.MaxRepeats"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int MaxRepeats {
get { return repeats; }
set { repeats = value; }
}
}
}

View File

@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <copyright file="MimeFormatter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.IO;
using System;
using System.Xml.Serialization;
using System.Reflection;
using System.Collections;
using System.Web.Services;
using System.Security.Permissions;
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public abstract class MimeFormatter {
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter.GetInitializer"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public abstract object GetInitializer(LogicalMethodInfo methodInfo);
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter.Initialize"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public abstract void Initialize(object initializer);
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter.GetInitializers"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual object[] GetInitializers(LogicalMethodInfo[] methodInfos) {
object[] initializers = new object[methodInfos.Length];
for (int i = 0; i < initializers.Length; i++)
initializers[i] = GetInitializer(methodInfos[i]);
return initializers;
}
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter.GetInitializer1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
public static object GetInitializer(Type type, LogicalMethodInfo methodInfo) {
return ((MimeFormatter)Activator.CreateInstance(type)).GetInitializer(methodInfo);
}
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter.GetInitializers1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
public static object[] GetInitializers(Type type, LogicalMethodInfo[] methodInfos) {
return ((MimeFormatter)Activator.CreateInstance(type)).GetInitializers(methodInfos);
}
/// <include file='doc\MimeFormatter.uex' path='docs/doc[@for="MimeFormatter.CreateInstance"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
public static MimeFormatter CreateInstance(Type type, object initializer) {
MimeFormatter formatter = (MimeFormatter)Activator.CreateInstance(type);
formatter.Initialize(initializer);
return formatter;
}
}
}

View File

@ -0,0 +1,29 @@
//------------------------------------------------------------------------------
// <copyright file="MimeParameterReader.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.IO;
using System;
using System.Xml.Serialization;
using System.Reflection;
using System.Collections;
using System.Web.Services;
using System.Security.Permissions;
/// <include file='doc\MimeParameterReader.uex' path='docs/doc[@for="MimeParameterReader"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class MimeParameterReader : MimeFormatter {
/// <include file='doc\MimeParameterReader.uex' path='docs/doc[@for="MimeParameterReader.Read"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public abstract object[] Read(HttpRequest request);
}
}

View File

@ -0,0 +1,59 @@
//------------------------------------------------------------------------------
// <copyright file="MimeParameterWriter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Services.Protocols {
using System.IO;
using System;
using System.Xml.Serialization;
using System.Reflection;
using System.Collections;
using System.Web.Services;
using System.Net;
using System.Text;
/// <include file='doc\MimeParameterWriter.uex' path='docs/doc[@for="MimeParameterWriter"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public abstract class MimeParameterWriter : MimeFormatter {
/// <include file='doc\MimeParameterWriter.uex' path='docs/doc[@for="MimeParameterWriter.UsesWriteRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual bool UsesWriteRequest { get { return false; } }
/// <include file='doc\MimeParameterWriter.uex' path='docs/doc[@for="MimeParameterWriter.RequestEncoding"]/*' />
public virtual Encoding RequestEncoding {
get { return null; }
set { }
}
/// <include file='doc\MimeParameterWriter.uex' path='docs/doc[@for="MimeParameterWriter.GetRequestUrl"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual string GetRequestUrl(string url, object[] parameters) {
return url;
}
/// <include file='doc\MimeParameterWriter.uex' path='docs/doc[@for="MimeParameterWriter.InitializeRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual void InitializeRequest(WebRequest request, object[] values) {
return;
}
/// <include file='doc\MimeParameterWriter.uex' path='docs/doc[@for="MimeParameterWriter.WriteRequest"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual void WriteRequest(Stream requestStream, object[] values) {
return;
}
}
}

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