2 // System.Web.Services.Description.SoapProtocolReflector.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // Copyright (C) Tim Coleman, 2002
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Web.Services;
33 using System.Web.Services.Protocols;
34 using System.Xml.Serialization;
35 using System.Xml.Schema;
38 namespace System.Web.Services.Description {
40 internal abstract class SoapProtocolReflector : ProtocolReflector
44 SoapBinding soapBinding;
50 public SoapProtocolReflector ()
54 #endregion // Constructors
58 public abstract SoapExtensionReflector ExtensionReflector { get; }
64 protected override void BeginClass ()
66 ExtensionReflector.ReflectDescription ();
69 protected override void EndClass ()
73 protected override bool ReflectMethod ()
75 SoapMethodStubInfo method = (SoapMethodStubInfo) MethodStubInfo;
76 bool existing = false;
78 if (Parent.MappedMessagesIn.ContainsKey (method.MethodInfo))
81 Parent.MappedMessagesIn [method.MethodInfo] = InputMessage;
82 Parent.MappedMessagesOut [method.MethodInfo] = OutputMessage;
86 ImportMessageParts ();
87 ExtensionReflector.ReflectMethod ();
92 void ImportMessageParts ()
94 SoapMethodStubInfo method = (SoapMethodStubInfo) MethodStubInfo;
95 ImportMessage (method.InputMembersMapping, InputMessage);
96 ImportMessage (method.OutputMembersMapping, OutputMessage);
99 foreach (SoapHeaderMapping hf in method.Headers)
101 if (hf.Custom) continue;
103 Message msg = new Message ();
104 msg.Name = Operation.Name + hf.HeaderType.Name;
105 MessagePart part = new MessagePart ();
106 part.Name = hf.HeaderType.Name;
107 msg.Parts.Add (part);
108 ServiceDescription.Messages.Add (msg);
110 if (method.Use == SoapBindingUse.Literal)
112 // MS.NET reflects header classes in a weird way. The root element
113 // name is the CLR class name unless it is specified in an XmlRootAttribute.
114 // The usual is to use the xml type name by default, but not in this case.
116 XmlRootAttribute root;
117 XmlAttributes ats = new XmlAttributes (hf.HeaderType);
118 if (ats.XmlRoot != null) root = ats.XmlRoot;
119 else root = new XmlRootAttribute (hf.HeaderType.Name);
121 if (root.Namespace == null) root.Namespace = TypeInfo.LogicalType.GetWebServiceLiteralNamespace (ServiceDescription.TargetNamespace);
122 if (root.ElementName == null) root.ElementName = hf.HeaderType.Name;
124 XmlTypeMapping mapping = ReflectionImporter.ImportTypeMapping (hf.HeaderType, root);
125 part.Element = new XmlQualifiedName (mapping.ElementName, mapping.Namespace);
126 SchemaExporter.ExportTypeMapping (mapping);
130 XmlTypeMapping mapping = SoapReflectionImporter.ImportTypeMapping (hf.HeaderType, TypeInfo.LogicalType.GetWebServiceEncodedNamespace (ServiceDescription.TargetNamespace));
131 part.Type = new XmlQualifiedName (mapping.ElementName, mapping.Namespace);
132 SoapSchemaExporter.ExportTypeMapping (mapping);
137 void ImportMessage (XmlMembersMapping members, Message msg)
139 SoapMethodStubInfo method = (SoapMethodStubInfo) MethodStubInfo;
140 bool needsEnclosingElement = (method.ParameterStyle == SoapParameterStyle.Wrapped &&
141 method.SoapBindingStyle == SoapBindingStyle.Document);
143 if (needsEnclosingElement)
145 MessagePart part = new MessagePart ();
146 part.Name = "parameters";
147 XmlQualifiedName qname = new XmlQualifiedName (members.ElementName, members.Namespace);
148 if (method.Use == SoapBindingUse.Literal) part.Element = qname;
149 else part.Type = qname;
150 msg.Parts.Add (part);
154 for (int n=0; n<members.Count; n++)
156 MessagePart part = new MessagePart ();
157 part.Name = members[n].MemberName;
159 if (method.Use == SoapBindingUse.Literal) {
161 part.Type = new XmlQualifiedName ("any", members[n].Namespace);
163 part.Element = new XmlQualifiedName (members[n].ElementName, members[n].Namespace);
166 string namesp = members[n].TypeNamespace;
167 if (namesp == "") namesp = members[n].Namespace;
168 part.Name = members[n].ElementName;
169 part.Type = new XmlQualifiedName (members[n].TypeName, namesp);
171 msg.Parts.Add (part);
176 if (method.Use == SoapBindingUse.Literal)
177 SchemaExporter.ExportMembersMapping (members);
179 SoapSchemaExporter.ExportMembersMapping (members, needsEnclosingElement);
182 protected override string ReflectMethodBinding ()
184 return ((SoapMethodStubInfo)MethodStubInfo).Binding;
190 internal class Soap11ProtocolReflector : SoapProtocolReflector
192 SoapExtensionReflector reflector;
194 public Soap11ProtocolReflector ()
196 reflector = new Soap11BindingExtensionReflector ();
197 reflector.ReflectionContext = this;
200 public override string ProtocolName {
201 get { return "Soap"; }
204 public override SoapExtensionReflector ExtensionReflector {
205 get { return reflector; }
209 internal class Soap12ProtocolReflector : SoapProtocolReflector
211 SoapExtensionReflector reflector;
213 public Soap12ProtocolReflector ()
215 reflector = new Soap12BindingExtensionReflector ();
216 reflector.ReflectionContext = this;
219 public override string ProtocolName {
220 get { return "Soap12"; }
223 public override SoapExtensionReflector ExtensionReflector {
224 get { return reflector; }