You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,57 @@
|
||||
namespace System.Web.Services.Description {
|
||||
using System.Xml.Serialization;
|
||||
using System.Web.Services.Configuration;
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpAddressBinding"]/*' />
|
||||
[XmlFormatExtension("address", HttpBinding.Namespace, typeof(Port))]
|
||||
public sealed class HttpAddressBinding : ServiceDescriptionFormatExtension {
|
||||
string location;
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpAddressBinding.Location"]/*' />
|
||||
[XmlAttribute("location")]
|
||||
public string Location {
|
||||
get { return location == null ? string.Empty : location; }
|
||||
set { location = value; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpBinding"]/*' />
|
||||
[XmlFormatExtension("binding", HttpBinding.Namespace, typeof(Binding))]
|
||||
[XmlFormatExtensionPrefix("http", HttpBinding.Namespace)]
|
||||
public sealed class HttpBinding : ServiceDescriptionFormatExtension {
|
||||
string verb;
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpBinding.Namespace"]/*' />
|
||||
public const string Namespace = "http://schemas.xmlsoap.org/wsdl/http/";
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpBinding.Verb"]/*' />
|
||||
[XmlAttribute("verb")]
|
||||
public string Verb {
|
||||
get { return verb; }
|
||||
set { verb = value; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpOperationBinding"]/*' />
|
||||
[XmlFormatExtension("operation", HttpBinding.Namespace, typeof(OperationBinding))]
|
||||
public sealed class HttpOperationBinding : ServiceDescriptionFormatExtension {
|
||||
string location;
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpOperationBinding.Location"]/*' />
|
||||
[XmlAttribute("location")]
|
||||
public string Location {
|
||||
get { return location == null ? string.Empty : location; }
|
||||
set { location = value; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpUrlEncodedBinding"]/*' />
|
||||
[XmlFormatExtension("urlEncoded", HttpBinding.Namespace, typeof(InputBinding))]
|
||||
public sealed class HttpUrlEncodedBinding : ServiceDescriptionFormatExtension {
|
||||
}
|
||||
|
||||
/// <include file='doc\HttpFormatExtensions.uex' path='docs/doc[@for="HttpUrlReplacementBinding"]/*' />
|
||||
[XmlFormatExtension("urlReplacement", HttpBinding.Namespace, typeof(InputBinding))]
|
||||
public sealed class HttpUrlReplacementBinding : ServiceDescriptionFormatExtension {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HttpGetProtocolImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
using System.Web.Services.Protocols;
|
||||
|
||||
internal class HttpGetProtocolImporter : HttpProtocolImporter {
|
||||
|
||||
public HttpGetProtocolImporter() : base(false) { }
|
||||
|
||||
public override string ProtocolName {
|
||||
get { return "HttpGet"; }
|
||||
}
|
||||
|
||||
internal override Type BaseClass {
|
||||
get {
|
||||
if (Style == ServiceDescriptionImportStyle.Client) {
|
||||
return typeof(HttpGetClientProtocol);
|
||||
}
|
||||
else {
|
||||
return typeof(WebService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool IsBindingSupported() {
|
||||
HttpBinding httpBinding = (HttpBinding)Binding.Extensions.Find(typeof(HttpBinding));
|
||||
if (httpBinding == null) return false;
|
||||
if (httpBinding.Verb != "GET") return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HttpGetProtocolReflector.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal class HttpGetProtocolReflector : HttpProtocolReflector {
|
||||
public override string ProtocolName {
|
||||
get { return "HttpGet"; }
|
||||
}
|
||||
|
||||
protected override void BeginClass() {
|
||||
if (IsEmptyBinding)
|
||||
return;
|
||||
HttpBinding httpBinding = new HttpBinding();
|
||||
httpBinding.Verb = "GET";
|
||||
Binding.Extensions.Add(httpBinding);
|
||||
HttpAddressBinding httpAddressBinding = new HttpAddressBinding();
|
||||
httpAddressBinding.Location = ServiceUrl;
|
||||
if (this.UriFixups != null)
|
||||
{
|
||||
this.UriFixups.Add(delegate(Uri current)
|
||||
{
|
||||
httpAddressBinding.Location = DiscoveryServerType.CombineUris(current, httpAddressBinding.Location);
|
||||
});
|
||||
}
|
||||
Port.Extensions.Add(httpAddressBinding);
|
||||
}
|
||||
|
||||
protected override bool ReflectMethod() {
|
||||
if (!ReflectUrlParameters()) return false;
|
||||
if (!ReflectMimeReturn()) return false;
|
||||
HttpOperationBinding httpOperationBinding = new HttpOperationBinding();
|
||||
httpOperationBinding.Location = MethodUrl;
|
||||
OperationBinding.Extensions.Add(httpOperationBinding);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HttpPostProtocolImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
using System.Web.Services.Protocols;
|
||||
|
||||
internal class HttpPostProtocolImporter : HttpProtocolImporter {
|
||||
|
||||
public HttpPostProtocolImporter() : base(true) { }
|
||||
|
||||
public override string ProtocolName {
|
||||
get { return "HttpPost"; }
|
||||
}
|
||||
|
||||
internal override Type BaseClass {
|
||||
get {
|
||||
if (Style == ServiceDescriptionImportStyle.Client) {
|
||||
return typeof(HttpPostClientProtocol);
|
||||
}
|
||||
else {
|
||||
return typeof(WebService);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override bool IsBindingSupported() {
|
||||
HttpBinding httpBinding = (HttpBinding)Binding.Extensions.Find(typeof(HttpBinding));
|
||||
if (httpBinding == null) return false;
|
||||
if (httpBinding.Verb != "POST") return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HttpPostProtocolReflector.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal class HttpPostProtocolReflector : HttpProtocolReflector {
|
||||
//HttpPostProtocolInfo protocolInfo;
|
||||
|
||||
//internal HttpPostProtocolInfoReflector() {
|
||||
//protocolInfo = new HttpPostProtocolInfo();
|
||||
//protocolInfo.Service = new HttpPostServiceInfo();
|
||||
//}
|
||||
|
||||
public override string ProtocolName {
|
||||
get { return "HttpPost"; }
|
||||
}
|
||||
|
||||
protected override void BeginClass() {
|
||||
if (IsEmptyBinding)
|
||||
return;
|
||||
HttpBinding httpBinding = new HttpBinding();
|
||||
httpBinding.Verb = "POST";
|
||||
Binding.Extensions.Add(httpBinding);
|
||||
HttpAddressBinding httpAddressBinding = new HttpAddressBinding();
|
||||
httpAddressBinding.Location = ServiceUrl;
|
||||
if (this.UriFixups != null)
|
||||
{
|
||||
this.UriFixups.Add(delegate(Uri current)
|
||||
{
|
||||
httpAddressBinding.Location = DiscoveryServerType.CombineUris(current, httpAddressBinding.Location);
|
||||
});
|
||||
}
|
||||
Port.Extensions.Add(httpAddressBinding);
|
||||
}
|
||||
|
||||
protected override bool ReflectMethod() {
|
||||
if (!ReflectMimeParameters()) return false;
|
||||
if (!ReflectMimeReturn()) return false;
|
||||
HttpOperationBinding httpOperationBinding = new HttpOperationBinding();
|
||||
httpOperationBinding.Location = MethodUrl;
|
||||
OperationBinding.Extensions.Add(httpOperationBinding);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HttpProtocolImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Web.Services.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.EnterpriseServices;
|
||||
|
||||
//
|
||||
internal class HttpMethodInfo {
|
||||
internal MimeParameterCollection UrlParameters;
|
||||
internal MimeParameterCollection MimeParameters;
|
||||
internal MimeReturn MimeReturn;
|
||||
internal string Name;
|
||||
internal string Href;
|
||||
}
|
||||
|
||||
internal abstract class HttpProtocolImporter : ProtocolImporter {
|
||||
MimeImporter[] importers;
|
||||
ArrayList[] importedParameters;
|
||||
ArrayList[] importedReturns;
|
||||
bool hasInputPayload;
|
||||
ArrayList codeClasses = new ArrayList();
|
||||
|
||||
protected HttpProtocolImporter(bool hasInputPayload) {
|
||||
Type[] importerTypes = WebServicesSection.Current.MimeImporterTypes;
|
||||
importers = new MimeImporter[importerTypes.Length];
|
||||
importedParameters = new ArrayList[importerTypes.Length];
|
||||
importedReturns = new ArrayList[importerTypes.Length];
|
||||
for (int i = 0; i < importers.Length; i++) {
|
||||
MimeImporter importer = (MimeImporter)Activator.CreateInstance(importerTypes[i]);
|
||||
importer.ImportContext = this;
|
||||
importedParameters[i] = new ArrayList();
|
||||
importedReturns[i] = new ArrayList();
|
||||
importers[i] = importer;
|
||||
}
|
||||
this.hasInputPayload = hasInputPayload;
|
||||
}
|
||||
|
||||
//
|
||||
MimeParameterCollection ImportMimeParameters() {
|
||||
for (int i = 0; i < importers.Length; i++) {
|
||||
MimeParameterCollection importedParameters = importers[i].ImportParameters();
|
||||
if (importedParameters != null) {
|
||||
this.importedParameters[i].Add(importedParameters);
|
||||
return importedParameters;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
MimeReturn ImportMimeReturn() {
|
||||
MimeReturn importedReturn;
|
||||
if (OperationBinding.Output.Extensions.Count == 0) {
|
||||
importedReturn = new MimeReturn();
|
||||
importedReturn.TypeName = typeof(void).FullName;
|
||||
return importedReturn;
|
||||
}
|
||||
for (int i = 0; i < importers.Length; i++) {
|
||||
importedReturn = importers[i].ImportReturn();
|
||||
if (importedReturn != null) {
|
||||
this.importedReturns[i].Add(importedReturn);
|
||||
return importedReturn;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
MimeParameterCollection ImportUrlParameters() {
|
||||
//
|
||||
HttpUrlEncodedBinding httpUrlEncodedBinding = (HttpUrlEncodedBinding)OperationBinding.Input.Extensions.Find(typeof(HttpUrlEncodedBinding));
|
||||
if (httpUrlEncodedBinding == null) return new MimeParameterCollection();
|
||||
return ImportStringParametersMessage();
|
||||
}
|
||||
|
||||
internal MimeParameterCollection ImportStringParametersMessage() {
|
||||
MimeParameterCollection parameters = new MimeParameterCollection();
|
||||
foreach (MessagePart part in InputMessage.Parts) {
|
||||
MimeParameter parameter = ImportUrlParameter(part);
|
||||
if (parameter == null) return null;
|
||||
parameters.Add(parameter);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
MimeParameter ImportUrlParameter(MessagePart part) {
|
||||
//
|
||||
MimeParameter parameter = new MimeParameter();
|
||||
parameter.Name = CodeIdentifier.MakeValid(XmlConvert.DecodeName(part.Name));
|
||||
parameter.TypeName = IsRepeatingParameter(part) ? typeof(string[]).FullName : typeof(string).FullName;
|
||||
return parameter;
|
||||
}
|
||||
|
||||
bool IsRepeatingParameter(MessagePart part) {
|
||||
XmlSchemaComplexType type = (XmlSchemaComplexType)Schemas.Find(part.Type, typeof(XmlSchemaComplexType));
|
||||
if (type == null) return false;
|
||||
if (type.ContentModel == null) return false;
|
||||
if (type.ContentModel.Content == null) throw new ArgumentException(Res.GetString(Res.Missing2, type.Name, type.ContentModel.GetType().Name), "part");
|
||||
if (type.ContentModel.Content is XmlSchemaComplexContentExtension) {
|
||||
return ((XmlSchemaComplexContentExtension)type.ContentModel.Content).BaseTypeName == new XmlQualifiedName(Soap.ArrayType, Soap.Encoding);
|
||||
}
|
||||
else if (type.ContentModel.Content is XmlSchemaComplexContentRestriction) {
|
||||
return ((XmlSchemaComplexContentRestriction)type.ContentModel.Content).BaseTypeName == new XmlQualifiedName(Soap.ArrayType, Soap.Encoding);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void AppendMetadata(CodeAttributeDeclarationCollection from, CodeAttributeDeclarationCollection to) {
|
||||
foreach (CodeAttributeDeclaration attr in from) to.Add(attr);
|
||||
}
|
||||
|
||||
CodeMemberMethod GenerateMethod(HttpMethodInfo method) {
|
||||
MimeParameterCollection parameters = method.MimeParameters != null ? method.MimeParameters : method.UrlParameters;
|
||||
|
||||
string[] parameterTypeNames = new string[parameters.Count];
|
||||
string[] parameterNames = new string[parameters.Count];
|
||||
|
||||
for (int i = 0; i < parameters.Count; i++) {
|
||||
MimeParameter param = parameters[i];
|
||||
parameterNames[i] = param.Name;
|
||||
parameterTypeNames[i] = param.TypeName;
|
||||
}
|
||||
|
||||
CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
|
||||
|
||||
CodeExpression[] formatterTypes = new CodeExpression[2];
|
||||
|
||||
if (method.MimeReturn.ReaderType == null) {
|
||||
formatterTypes[0] = new CodeTypeOfExpression(typeof(NopReturnReader).FullName);
|
||||
}
|
||||
else {
|
||||
formatterTypes[0] = new CodeTypeOfExpression(method.MimeReturn.ReaderType.FullName);
|
||||
}
|
||||
|
||||
if (method.MimeParameters != null)
|
||||
formatterTypes[1] = new CodeTypeOfExpression(method.MimeParameters.WriterType.FullName);
|
||||
else
|
||||
formatterTypes[1] = new CodeTypeOfExpression(typeof(UrlParameterWriter).FullName);
|
||||
|
||||
WebCodeGenerator.AddCustomAttribute(metadata, typeof(HttpMethodAttribute), formatterTypes, new string[0], new CodeExpression[0]);
|
||||
|
||||
|
||||
CodeMemberMethod mainCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, method.Name, new CodeFlags[parameterTypeNames.Length], parameterTypeNames, parameterNames,
|
||||
method.MimeReturn.TypeName, metadata,
|
||||
CodeFlags.IsPublic | (Style == ServiceDescriptionImportStyle.Client ? 0 : CodeFlags.IsAbstract));
|
||||
|
||||
AppendMetadata(method.MimeReturn.Attributes, mainCodeMethod.ReturnTypeCustomAttributes);
|
||||
|
||||
mainCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
|
||||
|
||||
for (int i = 0; i < parameters.Count; i++) {
|
||||
AppendMetadata(parameters[i].Attributes, mainCodeMethod.Parameters[i].CustomAttributes);
|
||||
}
|
||||
|
||||
if (Style == ServiceDescriptionImportStyle.Client) {
|
||||
bool oldAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateOldAsync) != 0;
|
||||
bool newAsync = (ServiceImporter.CodeGenerationOptions & CodeGenerationOptions.GenerateNewAsync) != 0 &&
|
||||
ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareEvents) &&
|
||||
ServiceImporter.CodeGenerator.Supports(GeneratorSupport.DeclareDelegates);
|
||||
|
||||
CodeExpression[] invokeParams = new CodeExpression[3];
|
||||
CreateInvokeParams(invokeParams, method, parameterNames);
|
||||
CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Invoke", invokeParams);
|
||||
if (method.MimeReturn.ReaderType != null) {
|
||||
mainCodeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, invoke)));
|
||||
}
|
||||
else {
|
||||
mainCodeMethod.Statements.Add(new CodeExpressionStatement(invoke));
|
||||
}
|
||||
|
||||
metadata = new CodeAttributeDeclarationCollection();
|
||||
|
||||
string[] asyncParameterTypeNames = new string[parameterTypeNames.Length + 2];
|
||||
parameterTypeNames.CopyTo(asyncParameterTypeNames, 0);
|
||||
asyncParameterTypeNames[parameterTypeNames.Length] = typeof(AsyncCallback).FullName;
|
||||
asyncParameterTypeNames[parameterTypeNames.Length + 1] = typeof(object).FullName;
|
||||
|
||||
string[] asyncParameterNames = new string[parameterNames.Length + 2];
|
||||
parameterNames.CopyTo(asyncParameterNames, 0);
|
||||
asyncParameterNames[parameterNames.Length] = "callback";
|
||||
asyncParameterNames[parameterNames.Length + 1] = "asyncState";
|
||||
|
||||
if (oldAsync) {
|
||||
CodeMemberMethod beginCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "Begin" + method.Name, new CodeFlags[asyncParameterTypeNames.Length],
|
||||
asyncParameterTypeNames, asyncParameterNames,
|
||||
typeof(IAsyncResult).FullName, metadata, CodeFlags.IsPublic);
|
||||
beginCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
|
||||
|
||||
invokeParams = new CodeExpression[5];
|
||||
CreateInvokeParams(invokeParams, method, parameterNames);
|
||||
|
||||
invokeParams[3] = new CodeArgumentReferenceExpression( "callback");
|
||||
invokeParams[4] = new CodeArgumentReferenceExpression( "asyncState");
|
||||
|
||||
invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "BeginInvoke", invokeParams);
|
||||
beginCodeMethod.Statements.Add(new CodeMethodReturnStatement(invoke));
|
||||
|
||||
CodeMemberMethod endCodeMethod = WebCodeGenerator.AddMethod(this.CodeTypeDeclaration, "End" + method.Name, new CodeFlags[1],
|
||||
new string[] { typeof(IAsyncResult).FullName },
|
||||
new string[] { "asyncResult" },
|
||||
method.MimeReturn.TypeName, metadata, CodeFlags.IsPublic);
|
||||
endCodeMethod.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
|
||||
|
||||
CodeExpression expr = new CodeArgumentReferenceExpression( "asyncResult");
|
||||
invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "EndInvoke", new CodeExpression[] { expr });
|
||||
if (method.MimeReturn.ReaderType != null) {
|
||||
endCodeMethod.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.MimeReturn.TypeName, invoke)));
|
||||
}
|
||||
else {
|
||||
endCodeMethod.Statements.Add(new CodeExpressionStatement(invoke));
|
||||
}
|
||||
}
|
||||
if (newAsync) {
|
||||
metadata = new CodeAttributeDeclarationCollection();
|
||||
string uniqueMethodName = method.Name;
|
||||
string methodKey = MethodSignature(uniqueMethodName, method.MimeReturn.TypeName, new CodeFlags[parameterTypeNames.Length], parameterTypeNames);
|
||||
DelegateInfo delegateInfo = (DelegateInfo)ExportContext[methodKey];
|
||||
if (delegateInfo == null) {
|
||||
string handlerType = ClassNames.AddUnique(uniqueMethodName + "CompletedEventHandler", uniqueMethodName);
|
||||
string handlerArgs = ClassNames.AddUnique(uniqueMethodName + "CompletedEventArgs", uniqueMethodName);
|
||||
delegateInfo = new DelegateInfo(handlerType, handlerArgs);
|
||||
}
|
||||
string handlerName = MethodNames.AddUnique(uniqueMethodName + "Completed", uniqueMethodName);
|
||||
string asyncName = MethodNames.AddUnique(uniqueMethodName + "Async", uniqueMethodName);
|
||||
string callbackMember = MethodNames.AddUnique(uniqueMethodName + "OperationCompleted", uniqueMethodName);
|
||||
string callbackName = MethodNames.AddUnique("On" + uniqueMethodName + "OperationCompleted", uniqueMethodName);
|
||||
|
||||
// public event xxxCompletedEventHandler xxxCompleted;
|
||||
WebCodeGenerator.AddEvent(this.CodeTypeDeclaration.Members, delegateInfo.handlerType, handlerName);
|
||||
|
||||
// private SendOrPostCallback xxxOperationCompleted;
|
||||
WebCodeGenerator.AddCallbackDeclaration(this.CodeTypeDeclaration.Members, callbackMember);
|
||||
|
||||
// create the pair of xxxAsync methods
|
||||
string userState = UniqueName("userState", parameterNames);
|
||||
CodeMemberMethod asyncCodeMethod = WebCodeGenerator.AddAsyncMethod(this.CodeTypeDeclaration, asyncName,
|
||||
parameterTypeNames, parameterNames, callbackMember, callbackName, userState);
|
||||
|
||||
// Generate InvokeAsync call
|
||||
invokeParams = new CodeExpression[5];
|
||||
CreateInvokeParams(invokeParams, method, parameterNames);
|
||||
invokeParams[3] = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember);
|
||||
invokeParams[4] = new CodeArgumentReferenceExpression(userState);
|
||||
|
||||
invoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InvokeAsync", invokeParams);
|
||||
asyncCodeMethod.Statements.Add(invoke);
|
||||
|
||||
// private void On_xxx_OperationCompleted(object arg) {..}
|
||||
bool methodHasReturn = method.MimeReturn.ReaderType != null;
|
||||
WebCodeGenerator.AddCallbackImplementation(this.CodeTypeDeclaration, callbackName, handlerName, delegateInfo.handlerArgs, methodHasReturn);
|
||||
if (ExportContext[methodKey] == null) {
|
||||
// public delegate void xxxCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs args);
|
||||
WebCodeGenerator.AddDelegate(ExtraCodeClasses, delegateInfo.handlerType, methodHasReturn ? delegateInfo.handlerArgs : typeof(AsyncCompletedEventArgs).FullName);
|
||||
|
||||
if (methodHasReturn) {
|
||||
ExtraCodeClasses.Add(WebCodeGenerator.CreateArgsClass(delegateInfo.handlerArgs, new string[] { method.MimeReturn.TypeName }, new string[] { "Result" },
|
||||
ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes)));
|
||||
}
|
||||
ExportContext[methodKey] = delegateInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mainCodeMethod;
|
||||
}
|
||||
|
||||
void CreateInvokeParams(CodeExpression[] invokeParams, HttpMethodInfo method, string[] parameterNames) {
|
||||
invokeParams[0] = new CodePrimitiveExpression(method.Name);
|
||||
|
||||
CodeExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Url");
|
||||
CodeExpression right = new CodePrimitiveExpression(method.Href);
|
||||
invokeParams[1] = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.Add, right);
|
||||
|
||||
CodeExpression[] values = new CodeExpression[parameterNames.Length];
|
||||
for (int i = 0; i < parameterNames.Length; i++) {
|
||||
values[i] = new CodeArgumentReferenceExpression( parameterNames[i]);
|
||||
}
|
||||
invokeParams[2] = new CodeArrayCreateExpression(typeof(object).FullName, values);
|
||||
}
|
||||
|
||||
protected override bool IsOperationFlowSupported(OperationFlow flow) {
|
||||
return flow == OperationFlow.RequestResponse;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
protected override CodeMemberMethod GenerateMethod() {
|
||||
HttpOperationBinding httpOperationBinding = (HttpOperationBinding)OperationBinding.Extensions.Find(typeof(HttpOperationBinding));
|
||||
if (httpOperationBinding == null) throw OperationBindingSyntaxException(Res.GetString(Res.MissingHttpOperationElement0));
|
||||
|
||||
HttpMethodInfo method = new HttpMethodInfo();
|
||||
|
||||
if (hasInputPayload) {
|
||||
method.MimeParameters = ImportMimeParameters();
|
||||
if (method.MimeParameters == null) {
|
||||
UnsupportedOperationWarning(Res.GetString(Res.NoInputMIMEFormatsWereRecognized0));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
method.UrlParameters = ImportUrlParameters();
|
||||
if (method.UrlParameters == null) {
|
||||
UnsupportedOperationWarning(Res.GetString(Res.NoInputHTTPFormatsWereRecognized0));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
method.MimeReturn = ImportMimeReturn();
|
||||
if (method.MimeReturn == null) {
|
||||
UnsupportedOperationWarning(Res.GetString(Res.NoOutputMIMEFormatsWereRecognized0));
|
||||
return null;
|
||||
}
|
||||
method.Name = MethodNames.AddUnique(MethodName, method);
|
||||
method.Href = httpOperationBinding.Location;
|
||||
return GenerateMethod(method);
|
||||
}
|
||||
|
||||
protected override CodeTypeDeclaration BeginClass() {
|
||||
MethodNames.Clear();
|
||||
ExtraCodeClasses.Clear();
|
||||
CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
|
||||
if (Style == ServiceDescriptionImportStyle.Client) {
|
||||
WebCodeGenerator.AddCustomAttribute(metadata, typeof(DebuggerStepThroughAttribute), new CodeExpression[0]);
|
||||
WebCodeGenerator.AddCustomAttribute(metadata, typeof(DesignerCategoryAttribute), new CodeExpression[] { new CodePrimitiveExpression("code") });
|
||||
}
|
||||
|
||||
Type[] requiredTypes = new Type[] {
|
||||
typeof(SoapDocumentMethodAttribute),
|
||||
typeof(XmlAttributeAttribute),
|
||||
typeof(WebService),
|
||||
typeof(Object),
|
||||
typeof(DebuggerStepThroughAttribute),
|
||||
typeof(DesignerCategoryAttribute),
|
||||
typeof(TransactionOption),
|
||||
};
|
||||
WebCodeGenerator.AddImports(this.CodeNamespace, WebCodeGenerator.GetNamespacesForTypes(requiredTypes));
|
||||
CodeFlags flags = 0;
|
||||
if (Style == ServiceDescriptionImportStyle.Server)
|
||||
flags = CodeFlags.IsAbstract;
|
||||
else if (Style == ServiceDescriptionImportStyle.ServerInterface)
|
||||
flags = CodeFlags.IsInterface;
|
||||
CodeTypeDeclaration codeClass = WebCodeGenerator.CreateClass(this.ClassName, BaseClass.FullName,
|
||||
new string[0], metadata, CodeFlags.IsPublic | flags,
|
||||
ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));
|
||||
|
||||
codeClass.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
|
||||
|
||||
CodeConstructor ctor = WebCodeGenerator.AddConstructor(codeClass, new string[0], new string[0], null, CodeFlags.IsPublic);
|
||||
ctor.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
|
||||
|
||||
HttpAddressBinding httpAddressBinding = Port == null ? null : (HttpAddressBinding)Port.Extensions.Find(typeof(HttpAddressBinding));
|
||||
string url = (httpAddressBinding != null) ? httpAddressBinding.Location : null;
|
||||
ServiceDescription serviceDescription = Binding.ServiceDescription;
|
||||
ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, serviceDescription.AppSettingUrlKey, serviceDescription.AppSettingBaseUrl, false);
|
||||
|
||||
codeClasses.Add(codeClass);
|
||||
return codeClass;
|
||||
}
|
||||
|
||||
protected override void EndNamespace() {
|
||||
for (int i = 0; i < importers.Length; i++) {
|
||||
importers[i].GenerateCode((MimeReturn[])importedReturns[i].ToArray(typeof(MimeReturn)),
|
||||
(MimeParameterCollection[])importedParameters[i].ToArray(typeof(MimeParameterCollection)));
|
||||
}
|
||||
|
||||
foreach (CodeTypeDeclaration codeClass in codeClasses) {
|
||||
if (codeClass.CustomAttributes == null)
|
||||
codeClass.CustomAttributes = new CodeAttributeDeclarationCollection();
|
||||
|
||||
for (int i = 0; i < importers.Length; i++) {
|
||||
importers[i].AddClassMetadata(codeClass);
|
||||
}
|
||||
}
|
||||
foreach (CodeTypeDeclaration declaration in ExtraCodeClasses) {
|
||||
this.CodeNamespace.Types.Add(declaration);
|
||||
}
|
||||
CodeGenerator.ValidateIdentifiers(CodeNamespace);
|
||||
}
|
||||
|
||||
internal abstract Type BaseClass { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="HttpProtocolReflector.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Web.Services.Configuration;
|
||||
|
||||
internal abstract class HttpProtocolReflector : ProtocolReflector {
|
||||
MimeReflector[] reflectors;
|
||||
|
||||
protected HttpProtocolReflector() {
|
||||
Type[] reflectorTypes = WebServicesSection.Current.MimeReflectorTypes;
|
||||
reflectors = new MimeReflector[reflectorTypes.Length];
|
||||
for (int i = 0; i < reflectors.Length; i++) {
|
||||
MimeReflector reflector = (MimeReflector)Activator.CreateInstance(reflectorTypes[i]);
|
||||
reflector.ReflectionContext = this;
|
||||
reflectors[i] = reflector;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool ReflectMimeParameters() {
|
||||
bool handled = false;
|
||||
for (int i = 0; i < reflectors.Length; i++) {
|
||||
if (reflectors[i].ReflectParameters())
|
||||
handled = true;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
protected bool ReflectMimeReturn() {
|
||||
if (Method.ReturnType == typeof(void)) {
|
||||
Message outputMessage = OutputMessage;
|
||||
return true;
|
||||
}
|
||||
bool handled = false;
|
||||
for (int i = 0; i < reflectors.Length; i++) {
|
||||
if (reflectors[i].ReflectReturn()) {
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
protected bool ReflectUrlParameters() {
|
||||
if (!HttpServerProtocol.AreUrlParametersSupported(Method))
|
||||
return false;
|
||||
ReflectStringParametersMessage();
|
||||
OperationBinding.Input.Extensions.Add(new HttpUrlEncodedBinding());
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void ReflectStringParametersMessage() {
|
||||
Message inputMessage = InputMessage;
|
||||
foreach (ParameterInfo parameterInfo in Method.InParameters) {
|
||||
MessagePart part = new MessagePart();
|
||||
part.Name = XmlConvert.EncodeLocalName(parameterInfo.Name);
|
||||
if (parameterInfo.ParameterType.IsArray) {
|
||||
string typeNs = DefaultNamespace;
|
||||
if (typeNs.EndsWith("/", StringComparison.Ordinal))
|
||||
typeNs += "AbstractTypes";
|
||||
else
|
||||
typeNs += "/AbstractTypes";
|
||||
string typeName = "StringArray";
|
||||
if (!ServiceDescription.Types.Schemas.Contains(typeNs)) {
|
||||
XmlSchema schema = new XmlSchema();
|
||||
schema.TargetNamespace = typeNs;
|
||||
ServiceDescription.Types.Schemas.Add(schema);
|
||||
|
||||
XmlSchemaElement element = new XmlSchemaElement();
|
||||
element.Name = "String";
|
||||
element.SchemaTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
|
||||
element.MinOccurs = decimal.Zero;
|
||||
element.MaxOccurs = decimal.MaxValue;
|
||||
XmlSchemaSequence all = new XmlSchemaSequence();
|
||||
all.Items.Add(element);
|
||||
|
||||
XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();
|
||||
restriction.BaseTypeName = new XmlQualifiedName(Soap.ArrayType, Soap.Encoding);
|
||||
restriction.Particle = all;
|
||||
|
||||
XmlSchemaImport import = new XmlSchemaImport();
|
||||
import.Namespace = restriction.BaseTypeName.Namespace;
|
||||
|
||||
XmlSchemaComplexContent model = new XmlSchemaComplexContent();
|
||||
model.Content = restriction;
|
||||
|
||||
XmlSchemaComplexType type = new XmlSchemaComplexType();
|
||||
type.Name = typeName;
|
||||
type.ContentModel = model;
|
||||
|
||||
schema.Items.Add(type);
|
||||
schema.Includes.Add(import);
|
||||
}
|
||||
part.Type = new XmlQualifiedName(typeName, typeNs);
|
||||
}
|
||||
else {
|
||||
part.Type = new XmlQualifiedName("string", XmlSchema.Namespace);
|
||||
}
|
||||
inputMessage.Parts.Add(part);
|
||||
}
|
||||
}
|
||||
|
||||
internal string MethodUrl {
|
||||
get {
|
||||
WebMethodAttribute methodAttribute = Method.MethodAttribute;
|
||||
string name = methodAttribute.MessageName;
|
||||
if (name.Length == 0) name = Method.Name;
|
||||
return "/" + name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeAnyImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.IO;
|
||||
|
||||
|
||||
internal class MimeAnyImporter : MimeImporter {
|
||||
|
||||
internal override MimeParameterCollection ImportParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
internal override MimeReturn ImportReturn() {
|
||||
if (ImportContext.OperationBinding.Output.Extensions.Count == 0) return null;
|
||||
MimeReturn importedReturn = new MimeReturn();
|
||||
importedReturn.TypeName = typeof(Stream).FullName;
|
||||
importedReturn.ReaderType = typeof(AnyReturnReader);
|
||||
return importedReturn;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeFormImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Globalization;
|
||||
|
||||
internal class MimeFormImporter : MimeImporter {
|
||||
|
||||
internal override MimeParameterCollection ImportParameters() {
|
||||
MimeContentBinding mimeContentBinding = (MimeContentBinding)ImportContext.OperationBinding.Input.Extensions.Find(typeof(MimeContentBinding));
|
||||
if (mimeContentBinding == null) return null;
|
||||
if (string.Compare(mimeContentBinding.Type, HtmlFormParameterReader.MimeType, StringComparison.OrdinalIgnoreCase) != 0) return null;
|
||||
MimeParameterCollection parameters = ImportContext.ImportStringParametersMessage();
|
||||
if (parameters == null) return null;
|
||||
parameters.WriterType = typeof(HtmlFormParameterWriter);
|
||||
return parameters;
|
||||
}
|
||||
|
||||
internal override MimeReturn ImportReturn() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeFormReflector.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal class MimeFormReflector : MimeReflector {
|
||||
internal override bool ReflectParameters() {
|
||||
if (!HtmlFormParameterReader.IsSupported(ReflectionContext.Method))
|
||||
return false;
|
||||
ReflectionContext.ReflectStringParametersMessage();
|
||||
MimeContentBinding mimeContentBinding = new MimeContentBinding();
|
||||
mimeContentBinding.Type = HtmlFormParameterReader.MimeType;
|
||||
ReflectionContext.OperationBinding.Input.Extensions.Add(mimeContentBinding);
|
||||
return true;
|
||||
}
|
||||
|
||||
internal override bool ReflectReturn() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
namespace System.Web.Services.Description {
|
||||
using System.Xml.Serialization;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Web.Services.Configuration;
|
||||
using System.Globalization;
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeContentBinding"]/*' />
|
||||
[XmlFormatExtension("content", MimeContentBinding.Namespace, typeof(MimePart), typeof(InputBinding), typeof(OutputBinding))]
|
||||
[XmlFormatExtensionPrefix("mime", MimeContentBinding.Namespace)]
|
||||
public sealed class MimeContentBinding : ServiceDescriptionFormatExtension {
|
||||
string type;
|
||||
string part;
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeContentBinding.Part"]/*' />
|
||||
[XmlAttribute("part")]
|
||||
public string Part {
|
||||
get { return part; }
|
||||
set { part = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeContentBinding.Type"]/*' />
|
||||
[XmlAttribute("type")]
|
||||
public string Type {
|
||||
get { return type == null ? string.Empty : type; }
|
||||
set { type = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeContentBinding.Namespace"]/*' />
|
||||
public const string Namespace = "http://schemas.xmlsoap.org/wsdl/mime/";
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePart"]/*' />
|
||||
[XmlFormatExtensionPoint("Extensions")]
|
||||
public sealed class MimePart : ServiceDescriptionFormatExtension {
|
||||
ServiceDescriptionFormatExtensionCollection extensions;
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePart.Extensions"]/*' />
|
||||
[XmlIgnore]
|
||||
public ServiceDescriptionFormatExtensionCollection Extensions {
|
||||
get { if (extensions == null) extensions = new ServiceDescriptionFormatExtensionCollection(this); return extensions; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeMultipartRelatedBinding"]/*' />
|
||||
[XmlFormatExtension("multipartRelated", MimeContentBinding.Namespace, typeof(InputBinding), typeof(OutputBinding))]
|
||||
public sealed class MimeMultipartRelatedBinding : ServiceDescriptionFormatExtension {
|
||||
MimePartCollection parts = new MimePartCollection();
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeMultipartRelatedBinding.Parts"]/*' />
|
||||
[XmlElement("part")]
|
||||
public MimePartCollection Parts {
|
||||
get { return parts; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeXmlBinding"]/*' />
|
||||
[XmlFormatExtension("mimeXml", MimeContentBinding.Namespace, typeof(MimePart), typeof(InputBinding), typeof(OutputBinding))]
|
||||
public sealed class MimeXmlBinding : ServiceDescriptionFormatExtension {
|
||||
string part;
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeXmlBinding.Part"]/*' />
|
||||
[XmlAttribute("part")]
|
||||
public string Part {
|
||||
get { return part; }
|
||||
set { part = value; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection"]/*' />
|
||||
public sealed class MimePartCollection : CollectionBase {
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.this"]/*' />
|
||||
public MimePart this[int index] {
|
||||
get { return (MimePart)List[index]; }
|
||||
set { List[index] = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.Add"]/*' />
|
||||
public int Add(MimePart mimePart) {
|
||||
return List.Add(mimePart);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.Insert"]/*' />
|
||||
public void Insert(int index, MimePart mimePart) {
|
||||
List.Insert(index, mimePart);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.IndexOf"]/*' />
|
||||
public int IndexOf(MimePart mimePart) {
|
||||
return List.IndexOf(mimePart);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.Contains"]/*' />
|
||||
public bool Contains(MimePart mimePart) {
|
||||
return List.Contains(mimePart);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.Remove"]/*' />
|
||||
public void Remove(MimePart mimePart) {
|
||||
List.Remove(mimePart);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimePartCollection.CopyTo"]/*' />
|
||||
public void CopyTo(MimePart[] array, int index) {
|
||||
List.CopyTo(array, index);
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextBinding"]/*' />
|
||||
[XmlFormatExtension("text", MimeTextBinding.Namespace, typeof(InputBinding), typeof(OutputBinding), typeof(MimePart))]
|
||||
[XmlFormatExtensionPrefix("tm", MimeTextBinding.Namespace)]
|
||||
public sealed class MimeTextBinding : ServiceDescriptionFormatExtension {
|
||||
MimeTextMatchCollection matches = new MimeTextMatchCollection();
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextBinding.Namespace"]/*' />
|
||||
public const string Namespace = "http://microsoft.com/wsdl/mime/textMatching/";
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextBinding.Matches"]/*' />
|
||||
[XmlElement("match", typeof(MimeTextMatch))]
|
||||
public MimeTextMatchCollection Matches {
|
||||
get { return matches; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch"]/*' />
|
||||
public sealed class MimeTextMatch {
|
||||
string name;
|
||||
string type;
|
||||
int repeats = 1;
|
||||
string pattern;
|
||||
int group = 1;
|
||||
int capture = 0;
|
||||
bool ignoreCase = false;
|
||||
MimeTextMatchCollection matches = new MimeTextMatchCollection();
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Name"]/*' />
|
||||
[XmlAttribute("name")]
|
||||
public string Name {
|
||||
get { return name == null ? string.Empty : name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Type"]/*' />
|
||||
[XmlAttribute("type")]
|
||||
public string Type {
|
||||
get { return type == null ? string.Empty : type; }
|
||||
set { type = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Group"]/*' />
|
||||
[XmlAttribute("group"), DefaultValue(1)]
|
||||
public int Group {
|
||||
get { return group; }
|
||||
set {
|
||||
if (value < 0) throw new ArgumentException(Res.GetString(Res.WebNegativeValue, "group"));
|
||||
group = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Capture"]/*' />
|
||||
[XmlAttribute("capture"), DefaultValue(0)]
|
||||
public int Capture {
|
||||
get { return capture; }
|
||||
set {
|
||||
if (value < 0) throw new ArgumentException(Res.GetString(Res.WebNegativeValue, "capture"));
|
||||
capture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Repeats"]/*' />
|
||||
[XmlIgnore()]
|
||||
public int Repeats {
|
||||
get { return repeats; }
|
||||
set {
|
||||
if (value < 0) throw new ArgumentException(Res.GetString(Res.WebNegativeValue, "repeats"));
|
||||
repeats = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.RepeatsString"]/*' />
|
||||
[XmlAttribute("repeats"), DefaultValue("1")]
|
||||
public string RepeatsString {
|
||||
get { return repeats == int.MaxValue ? "*" : repeats.ToString(CultureInfo.InvariantCulture); }
|
||||
set {
|
||||
if (value == "*")
|
||||
repeats = int.MaxValue;
|
||||
else
|
||||
Repeats = int.Parse(value, CultureInfo.InvariantCulture); // pass through our setter for arg checking
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Pattern"]/*' />
|
||||
[XmlAttribute("pattern")]
|
||||
public string Pattern {
|
||||
get { return pattern == null ? string.Empty : pattern; }
|
||||
set { this.pattern = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.IgnoreCase"]/*' />
|
||||
[XmlAttribute("ignoreCase")]
|
||||
public bool IgnoreCase {
|
||||
get { return ignoreCase; }
|
||||
set { ignoreCase = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatch.Matches"]/*' />
|
||||
[XmlElement("match")]
|
||||
public MimeTextMatchCollection Matches {
|
||||
get { return matches; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection"]/*' />
|
||||
public sealed class MimeTextMatchCollection : CollectionBase {
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.this"]/*' />
|
||||
public MimeTextMatch this[int index] {
|
||||
get { return (MimeTextMatch)List[index]; }
|
||||
set { List[index] = value; }
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.Add"]/*' />
|
||||
public int Add(MimeTextMatch match) {
|
||||
return List.Add(match);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.Insert"]/*' />
|
||||
public void Insert(int index, MimeTextMatch match) {
|
||||
List.Insert(index, match);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.IndexOf"]/*' />
|
||||
public int IndexOf(MimeTextMatch match) {
|
||||
return List.IndexOf(match);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.Contains"]/*' />
|
||||
public bool Contains(MimeTextMatch match) {
|
||||
return List.Contains(match);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.Remove"]/*' />
|
||||
public void Remove(MimeTextMatch match) {
|
||||
List.Remove(match);
|
||||
}
|
||||
|
||||
/// <include file='doc\MimeFormatExtensions.uex' path='docs/doc[@for="MimeTextMatchCollection.CopyTo"]/*' />
|
||||
public void CopyTo(MimeTextMatch[] array, int index) {
|
||||
List.CopyTo(array, index);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.CodeDom;
|
||||
|
||||
internal abstract class MimeImporter {
|
||||
HttpProtocolImporter protocol;
|
||||
|
||||
internal abstract MimeParameterCollection ImportParameters();
|
||||
internal abstract MimeReturn ImportReturn();
|
||||
|
||||
internal virtual void GenerateCode(MimeReturn[] importedReturns, MimeParameterCollection[] importedParameters) {
|
||||
}
|
||||
|
||||
internal virtual void AddClassMetadata(CodeTypeDeclaration codeClass) {
|
||||
}
|
||||
|
||||
internal HttpProtocolImporter ImportContext {
|
||||
get { return protocol; }
|
||||
set { protocol = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeParameter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.CodeDom;
|
||||
|
||||
internal class MimeParameter {
|
||||
string name;
|
||||
string typeName;
|
||||
CodeAttributeDeclarationCollection attrs;
|
||||
|
||||
internal string Name {
|
||||
get { return name == null ? string.Empty : name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
internal string TypeName {
|
||||
get { return typeName == null ? string.Empty : typeName; }
|
||||
set { typeName = value; }
|
||||
}
|
||||
|
||||
internal CodeAttributeDeclarationCollection Attributes {
|
||||
get {
|
||||
if (attrs == null)
|
||||
attrs = new CodeAttributeDeclarationCollection();
|
||||
return attrs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeParameters.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal class MimeParameterCollection : CollectionBase {
|
||||
Type writerType;
|
||||
|
||||
internal Type WriterType {
|
||||
get { return writerType; }
|
||||
set { writerType = value; }
|
||||
}
|
||||
|
||||
internal MimeParameter this[int index] {
|
||||
get { return (MimeParameter)List[index]; }
|
||||
set { List[index] = value; }
|
||||
}
|
||||
|
||||
internal int Add(MimeParameter parameter) {
|
||||
return List.Add(parameter);
|
||||
}
|
||||
|
||||
internal void Insert(int index, MimeParameter parameter) {
|
||||
List.Insert(index, parameter);
|
||||
}
|
||||
|
||||
internal int IndexOf(MimeParameter parameter) {
|
||||
return List.IndexOf(parameter);
|
||||
}
|
||||
|
||||
internal bool Contains(MimeParameter parameter) {
|
||||
return List.Contains(parameter);
|
||||
}
|
||||
|
||||
internal void Remove(MimeParameter parameter) {
|
||||
List.Remove(parameter);
|
||||
}
|
||||
|
||||
internal void CopyTo(MimeParameter[] array, int index) {
|
||||
List.CopyTo(array, index);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeReflector.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
internal abstract class MimeReflector {
|
||||
HttpProtocolReflector protocol;
|
||||
|
||||
internal abstract bool ReflectParameters();
|
||||
internal abstract bool ReflectReturn();
|
||||
|
||||
internal HttpProtocolReflector ReflectionContext {
|
||||
get { return protocol; }
|
||||
set { protocol = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeReturn.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.CodeDom;
|
||||
|
||||
internal class MimeReturn {
|
||||
string typeName;
|
||||
Type readerType;
|
||||
CodeAttributeDeclarationCollection attrs;
|
||||
|
||||
internal string TypeName {
|
||||
get { return typeName == null ? string.Empty : typeName; }
|
||||
set { typeName = value; }
|
||||
}
|
||||
|
||||
internal Type ReaderType {
|
||||
get { return readerType; }
|
||||
set { readerType = value; }
|
||||
}
|
||||
|
||||
internal CodeAttributeDeclarationCollection Attributes {
|
||||
get {
|
||||
if (attrs == null)
|
||||
attrs = new CodeAttributeDeclarationCollection();
|
||||
return attrs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
internal class MimeTextReturn : MimeReturn {
|
||||
MimeTextBinding textBinding;
|
||||
|
||||
internal MimeTextBinding TextBinding {
|
||||
get { return textBinding; }
|
||||
set { textBinding = value; }
|
||||
}
|
||||
}
|
||||
|
||||
internal class MimeTextImporter : MimeImporter {
|
||||
string methodName;
|
||||
|
||||
internal override MimeParameterCollection ImportParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
internal override MimeReturn ImportReturn() {
|
||||
MimeTextBinding mimeTextBinding = (MimeTextBinding)ImportContext.OperationBinding.Output.Extensions.Find(typeof(MimeTextBinding));
|
||||
if (mimeTextBinding == null) return null;
|
||||
if (mimeTextBinding.Matches.Count == 0) {
|
||||
ImportContext.UnsupportedOperationBindingWarning(Res.GetString(Res.MissingMatchElement0));
|
||||
return null;
|
||||
}
|
||||
methodName = CodeIdentifier.MakeValid(ImportContext.OperationBinding.Name);
|
||||
|
||||
MimeTextReturn importedReturn = new MimeTextReturn();
|
||||
importedReturn.TypeName = ImportContext.ClassNames.AddUnique(methodName + "Matches", mimeTextBinding);
|
||||
importedReturn.TextBinding = mimeTextBinding;
|
||||
importedReturn.ReaderType = typeof(TextReturnReader);
|
||||
return importedReturn;
|
||||
}
|
||||
|
||||
internal override void GenerateCode(MimeReturn[] importedReturns, MimeParameterCollection[] importedParameters) {
|
||||
for (int i = 0; i < importedReturns.Length; i++) {
|
||||
if (importedReturns[i] is MimeTextReturn) {
|
||||
GenerateCode((MimeTextReturn)importedReturns[i], ImportContext.ServiceImporter.CodeGenerationOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateCode(MimeTextReturn importedReturn, CodeGenerationOptions options) {
|
||||
GenerateCode(importedReturn.TypeName, importedReturn.TextBinding.Matches, options);
|
||||
}
|
||||
|
||||
void GenerateCode(string typeName, MimeTextMatchCollection matches, CodeGenerationOptions options) {
|
||||
CodeIdentifiers members = new CodeIdentifiers();
|
||||
CodeTypeDeclaration codeClass = WebCodeGenerator.AddClass(ImportContext.CodeNamespace, typeName, string.Empty, new string[0], null, CodeFlags.IsPublic,
|
||||
ImportContext.ServiceImporter.CodeGenerator.Supports(GeneratorSupport.PartialTypes));
|
||||
|
||||
string[] fieldTypeNames = new string[matches.Count];
|
||||
for (int i = 0; i < matches.Count; i++) {
|
||||
MimeTextMatch match = matches[i];
|
||||
string name = members.AddUnique(CodeIdentifier.MakeValid(match.Name.Length == 0 ? methodName + "Match" : match.Name), match);
|
||||
CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
|
||||
if (match.Pattern.Length == 0) throw new ArgumentException(Res.GetString(Res.WebTextMatchMissingPattern));
|
||||
|
||||
CodeExpression pattern = new CodePrimitiveExpression(match.Pattern);
|
||||
int numPropValues = 0;
|
||||
if (match.Group != 1)
|
||||
numPropValues++;
|
||||
if (match.Capture != 0)
|
||||
numPropValues++;
|
||||
if (match.IgnoreCase)
|
||||
numPropValues++;
|
||||
if (match.Repeats != 1 && match.Repeats != int.MaxValue)
|
||||
numPropValues++;
|
||||
CodeExpression[] propertyValues = new CodeExpression[numPropValues];
|
||||
string[] propertyNames = new string[propertyValues.Length];
|
||||
numPropValues = 0;
|
||||
if (match.Group != 1) {
|
||||
propertyValues[numPropValues] = new CodePrimitiveExpression(match.Group);
|
||||
propertyNames[numPropValues] = "Group";
|
||||
numPropValues++;
|
||||
}
|
||||
if (match.Capture != 0) {
|
||||
propertyValues[numPropValues] = new CodePrimitiveExpression(match.Capture);
|
||||
propertyNames[numPropValues] = "Capture";
|
||||
numPropValues++;
|
||||
}
|
||||
if (match.IgnoreCase) {
|
||||
propertyValues[numPropValues] = new CodePrimitiveExpression(match.IgnoreCase);
|
||||
propertyNames[numPropValues] = "IgnoreCase";
|
||||
numPropValues++;
|
||||
}
|
||||
if (match.Repeats != 1 && match.Repeats != int.MaxValue) {
|
||||
propertyValues[numPropValues] = new CodePrimitiveExpression(match.Repeats);
|
||||
propertyNames[numPropValues] = "MaxRepeats";
|
||||
numPropValues++;
|
||||
}
|
||||
WebCodeGenerator.AddCustomAttribute(metadata, typeof(MatchAttribute), new CodeExpression[] { pattern }, propertyNames, propertyValues);
|
||||
|
||||
string fieldTypeName;
|
||||
if (match.Matches.Count > 0) {
|
||||
fieldTypeName = ImportContext.ClassNames.AddUnique(CodeIdentifier.MakeValid(match.Type.Length == 0 ? name : match.Type), match);
|
||||
fieldTypeNames[i] = fieldTypeName;
|
||||
}
|
||||
else {
|
||||
fieldTypeName = typeof(string).FullName;
|
||||
}
|
||||
if (match.Repeats != 1)
|
||||
fieldTypeName += "[]";
|
||||
|
||||
CodeTypeMember member = WebCodeGenerator.AddMember(codeClass, fieldTypeName, name, null, metadata, CodeFlags.IsPublic, options);
|
||||
|
||||
if (match.Matches.Count == 0 && match.Type.Length > 0) {
|
||||
ImportContext.Warnings |= ServiceDescriptionImportWarnings.OptionalExtensionsIgnored;
|
||||
ProtocolImporter.AddWarningComment(member.Comments, Res.GetString(Res.WebTextMatchIgnoredTypeWarning));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < fieldTypeNames.Length; i++) {
|
||||
string fieldTypeName = fieldTypeNames[i];
|
||||
if (fieldTypeName != null) {
|
||||
GenerateCode(fieldTypeName, matches[i].Matches, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeXmlImporter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.Services.Description {
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Serialization.Advanced;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml;
|
||||
using System.Data;
|
||||
using System.CodeDom;
|
||||
|
||||
internal class MimeXmlReturn : MimeReturn {
|
||||
XmlTypeMapping mapping;
|
||||
|
||||
internal XmlTypeMapping TypeMapping {
|
||||
get { return mapping; }
|
||||
set { mapping = value; }
|
||||
}
|
||||
}
|
||||
|
||||
internal class MimeXmlImporter : MimeImporter {
|
||||
XmlSchemaImporter importer;
|
||||
XmlCodeExporter exporter;
|
||||
|
||||
internal override MimeParameterCollection ImportParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
internal override MimeReturn ImportReturn() {
|
||||
MimeContentBinding mimeContentBinding = (MimeContentBinding)ImportContext.OperationBinding.Output.Extensions.Find(typeof(MimeContentBinding));
|
||||
if (mimeContentBinding != null) {
|
||||
if (!ContentType.MatchesBase(mimeContentBinding.Type, ContentType.TextXml)) {
|
||||
return null;
|
||||
}
|
||||
MimeReturn importedReturn = new MimeReturn();
|
||||
importedReturn.TypeName = typeof(XmlElement).FullName;
|
||||
importedReturn.ReaderType = typeof(XmlReturnReader);
|
||||
return importedReturn;
|
||||
}
|
||||
|
||||
MimeXmlBinding mimeXmlBinding = (MimeXmlBinding)ImportContext.OperationBinding.Output.Extensions.Find(typeof(MimeXmlBinding));
|
||||
if (mimeXmlBinding != null) {
|
||||
MimeXmlReturn importedReturn = new MimeXmlReturn();
|
||||
MessagePart part;
|
||||
switch (ImportContext.OutputMessage.Parts.Count) {
|
||||
case 0:
|
||||
throw new InvalidOperationException(Res.GetString(Res.MessageHasNoParts1, ImportContext.InputMessage.Name));
|
||||
case 1:
|
||||
if (mimeXmlBinding.Part == null || mimeXmlBinding.Part.Length == 0) {
|
||||
part = ImportContext.OutputMessage.Parts[0];
|
||||
}
|
||||
else {
|
||||
part = ImportContext.OutputMessage.FindPartByName(mimeXmlBinding.Part);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
part = ImportContext.OutputMessage.FindPartByName(mimeXmlBinding.Part);
|
||||
break;
|
||||
}
|
||||
importedReturn.TypeMapping = Importer.ImportTypeMapping(part.Element);
|
||||
importedReturn.TypeName = importedReturn.TypeMapping.TypeFullName;
|
||||
importedReturn.ReaderType = typeof(XmlReturnReader);
|
||||
Exporter.AddMappingMetadata(importedReturn.Attributes, importedReturn.TypeMapping, string.Empty);
|
||||
return importedReturn;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
XmlSchemaImporter Importer {
|
||||
get {
|
||||
if (importer == null) {
|
||||
importer = new XmlSchemaImporter(ImportContext.ConcreteSchemas, ImportContext.ServiceImporter.CodeGenerationOptions, ImportContext.ServiceImporter.CodeGenerator, ImportContext.ImportContext);
|
||||
foreach (Type extensionType in ImportContext.ServiceImporter.Extensions) {
|
||||
importer.Extensions.Add(extensionType.FullName, extensionType);
|
||||
}
|
||||
importer.Extensions.Add(new System.Data.Design.TypedDataSetSchemaImporterExtension());
|
||||
importer.Extensions.Add(new DataSetSchemaImporterExtension());
|
||||
}
|
||||
return importer;
|
||||
}
|
||||
}
|
||||
|
||||
XmlCodeExporter Exporter {
|
||||
get {
|
||||
if (exporter == null)
|
||||
exporter = new XmlCodeExporter(ImportContext.CodeNamespace, ImportContext.ServiceImporter.CodeCompileUnit,
|
||||
ImportContext.ServiceImporter.CodeGenerator, ImportContext.ServiceImporter.CodeGenerationOptions, ImportContext.ExportContext);
|
||||
return exporter;
|
||||
}
|
||||
}
|
||||
|
||||
internal override void GenerateCode(MimeReturn[] importedReturns, MimeParameterCollection[] importedParameters) {
|
||||
for (int i = 0; i < importedReturns.Length; i++) {
|
||||
if (importedReturns[i] is MimeXmlReturn) {
|
||||
GenerateCode((MimeXmlReturn)importedReturns[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateCode(MimeXmlReturn importedReturn) {
|
||||
Exporter.ExportTypeMapping(importedReturn.TypeMapping);
|
||||
}
|
||||
|
||||
internal override void AddClassMetadata(CodeTypeDeclaration codeClass) {
|
||||
foreach (CodeAttributeDeclaration attribute in Exporter.IncludeMetadata) {
|
||||
codeClass.CustomAttributes.Add(attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MimeXmlReflector.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.Services.Description {
|
||||
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Schema;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
|
||||
internal class MimeXmlReflector : MimeReflector {
|
||||
internal override bool ReflectParameters() {
|
||||
return false;
|
||||
}
|
||||
|
||||
internal override bool ReflectReturn() {
|
||||
MessagePart part = new MessagePart();
|
||||
part.Name = "Body";
|
||||
ReflectionContext.OutputMessage.Parts.Add(part);
|
||||
|
||||
if (typeof(XmlNode).IsAssignableFrom(ReflectionContext.Method.ReturnType)) {
|
||||
MimeContentBinding mimeContentBinding = new MimeContentBinding();
|
||||
mimeContentBinding.Type = "text/xml";
|
||||
mimeContentBinding.Part = part.Name;
|
||||
ReflectionContext.OperationBinding.Output.Extensions.Add(mimeContentBinding);
|
||||
}
|
||||
else {
|
||||
MimeXmlBinding mimeXmlBinding = new MimeXmlBinding();
|
||||
mimeXmlBinding.Part = part.Name;
|
||||
|
||||
LogicalMethodInfo methodInfo = ReflectionContext.Method;
|
||||
XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
|
||||
XmlTypeMapping xmlTypeMapping = ReflectionContext.ReflectionImporter.ImportTypeMapping(methodInfo.ReturnType, a.XmlRoot);
|
||||
xmlTypeMapping.SetKey(methodInfo.GetKey() + ":Return");
|
||||
ReflectionContext.SchemaExporter.ExportTypeMapping(xmlTypeMapping);
|
||||
part.Element = new XmlQualifiedName(xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace);
|
||||
ReflectionContext.OperationBinding.Output.Extensions.Add(mimeXmlBinding);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user