1 //------------------------------------------------------------------------------
2 // <copyright file="MimeXmlReflector.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.Services.Description {
8 
9     using System.Web.Services;
10     using System.Web.Services.Protocols;
11     using System.Xml.Serialization;
12     using System.Xml.Schema;
13     using System.Collections;
14     using System;
15     using System.Reflection;
16     using System.Xml;
17 
18     internal class MimeXmlReflector : MimeReflector {
ReflectParameters()19         internal override bool ReflectParameters() {
20             return false;
21         }
22 
ReflectReturn()23         internal override bool ReflectReturn() {
24             MessagePart part = new MessagePart();
25             part.Name = "Body";
26             ReflectionContext.OutputMessage.Parts.Add(part);
27 
28             if (typeof(XmlNode).IsAssignableFrom(ReflectionContext.Method.ReturnType)) {
29                 MimeContentBinding mimeContentBinding = new MimeContentBinding();
30                 mimeContentBinding.Type = "text/xml";
31                 mimeContentBinding.Part = part.Name;
32                 ReflectionContext.OperationBinding.Output.Extensions.Add(mimeContentBinding);
33             }
34             else {
35                 MimeXmlBinding mimeXmlBinding = new MimeXmlBinding();
36                 mimeXmlBinding.Part = part.Name;
37 
38                 LogicalMethodInfo methodInfo = ReflectionContext.Method;
39                 XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
40                 XmlTypeMapping xmlTypeMapping = ReflectionContext.ReflectionImporter.ImportTypeMapping(methodInfo.ReturnType, a.XmlRoot);
41                 xmlTypeMapping.SetKey(methodInfo.GetKey() + ":Return");
42                 ReflectionContext.SchemaExporter.ExportTypeMapping(xmlTypeMapping);
43                 part.Element = new XmlQualifiedName(xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace);
44                 ReflectionContext.OperationBinding.Output.Extensions.Add(mimeXmlBinding);
45             }
46 
47             return true;
48         }
49     }
50 }
51