2006-11-02 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / HttpSimpleProtocolReflector.cs
1 // 
2 // System.Web.Services.Description.HttpSimpleProtocolReflector.cs
3 //
4 // Author:
5 //   Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc.
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Web.Services;
32 using System.Web.Services.Protocols;
33 using System.Xml.Serialization;
34 using System.Xml;
35 using System.Xml.Schema;
36 using System.Reflection;
37
38 namespace System.Web.Services.Description {
39
40         internal abstract class HttpSimpleProtocolReflector : ProtocolReflector 
41         {
42                 #region Fields
43
44                 SoapBinding soapBinding;
45
46                 #endregion // Fields
47
48                 #region Constructors
49
50                 public HttpSimpleProtocolReflector ()
51                 {
52                 }
53                 
54                 #endregion // Constructors
55
56                 #region Methods
57
58                 protected override void BeginClass ()
59                 {
60                         HttpAddressBinding abind = new HttpAddressBinding ();
61                         abind.Location = ServiceUrl;
62                         Port.Extensions.Add (abind);
63                 }
64
65                 protected override void EndClass ()
66                 {
67                 }
68
69                 protected override bool ReflectMethod ()
70                 {
71                         LogicalTypeInfo ti = TypeStubManager.GetLogicalTypeInfo (ServiceType);
72                         HttpOperationBinding sob = new HttpOperationBinding();
73                         sob.Location = "/" + MethodStubInfo.Name;
74                         OperationBinding.Extensions.Add (sob);
75                         
76                         if (!Method.IsVoid)
77                         {
78                                 MimeXmlBinding mxb = new MimeXmlBinding ();
79                                 mxb.Part = "Body";
80                                 OperationBinding.Output.Extensions.Add (mxb);
81                         
82                                 MessagePart part = new MessagePart ();
83                                 part.Name = "Body";     
84                                 
85                                 XmlTypeMapping map = ReflectionImporter.ImportTypeMapping (Method.ReturnType, ti.GetWebServiceLiteralNamespace (ServiceDescription.TargetNamespace));
86                                 XmlQualifiedName qname = new XmlQualifiedName (map.ElementName, map.Namespace);
87                                 part.Element = qname;
88                                 OutputMessage.Parts.Add (part);
89                                 SchemaExporter.ExportTypeMapping (map);
90                         }
91                         
92                         XmlReflectionMember[] mems = new XmlReflectionMember [Method.Parameters.Length];
93                         for (int n=0; n<Method.Parameters.Length; n++)
94                         {
95                                 ParameterInfo param = Method.Parameters [n];
96                                 XmlReflectionMember mem = new XmlReflectionMember ();
97                                 mem.MemberName = param.Name;
98                                 Type ptype = param.ParameterType;
99                                 if (ptype.IsByRef) ptype = ptype.GetElementType ();
100                                 mem.MemberType = ptype;
101                                 mems [n] = mem;
102                         }
103                         
104                         XmlMembersMapping memap = ReflectionImporter.ImportMembersMapping ("", ti.WebServiceAbstractNamespace, mems, false);
105                         bool allPrimitives = true;
106                         
107                         for (int n=0; n<memap.Count; n++)
108                         {
109                                 XmlMemberMapping mem = memap[n];
110                                 MessagePart part = new MessagePart ();
111                                 XmlQualifiedName pqname;
112                                 
113                                 if (mem.TypeNamespace == "") 
114                                         pqname = new XmlQualifiedName (mem.TypeName, XmlSchema.Namespace);
115                                 else {
116                                         pqname = new XmlQualifiedName (mem.TypeName, mem.TypeNamespace); 
117                                         allPrimitives = false; 
118                                 }
119
120                                 part.Type = pqname;
121                                 part.Name = mem.ElementName;
122                                 InputMessage.Parts.Add (part);
123                         }
124
125                         if (!allPrimitives)
126                                 SoapSchemaExporter.ExportMembersMapping (memap);
127                         
128                         return true;
129                 }
130                 
131                 XmlQualifiedName GenerateStringArray ()
132                 {
133                         return null;
134                 }
135
136                 protected override string ReflectMethodBinding ()
137                 {
138                         return null;
139                 }
140
141                 #endregion
142         }
143 }