* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / ServiceDescriptionReflector.cs
index f2d2c493dac4e53f0c72dc63a8d3f00276051422..14d2a9c65952411929817f06fe89b98c05b373f0 100644 (file)
@@ -7,23 +7,40 @@
 //\r
 // Copyright (C) Tim Coleman, 2002\r
 //\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 \r
 using System.Web.Services;\r
 using System.Xml.Serialization;\r
 using System.Xml;\r
+using System.Xml.Schema;\r
 using System.Web.Services.Protocols;\r
+using System.Web.Services.Configuration;\r
 \r
 namespace System.Web.Services.Description {\r
-       public class ServiceDescriptionReflector {\r
-\r
-               #region Fields\r
-\r
-               Types types;\r
+       public class ServiceDescriptionReflector \r
+       {\r
                ServiceDescriptionCollection serviceDescriptions;\r
-               XmlSchemaExporter schemaExporter;\r
-               SoapSchemaExporter soapSchemaExporter;\r
-\r
-               #endregion // Fields\r
+               Types types;\r
 \r
                #region Constructors\r
        \r
@@ -31,8 +48,6 @@ namespace System.Web.Services.Description {
                {\r
                        types = new Types ();\r
                        serviceDescriptions = new ServiceDescriptionCollection ();\r
-                       schemaExporter = new XmlSchemaExporter (types.Schemas);\r
-                       soapSchemaExporter = new SoapSchemaExporter (types.Schemas);\r
                }\r
                \r
                #endregion // Constructors\r
@@ -47,204 +62,41 @@ namespace System.Web.Services.Description {
                        get { return serviceDescriptions; }\r
                }\r
 \r
-       \r
+\r
                #endregion // Properties\r
 \r
                #region Methods\r
 \r
-               [MonoTODO]\r
                public void Reflect (Type type, string url)\r
                {\r
-                       ServiceDescription desc = new ServiceDescription ();\r
-                       serviceDescriptions.Add (desc);\r
+                       XmlSchemaExporter schemaExporter = new XmlSchemaExporter (Schemas);\r
+                       SoapSchemaExporter soapSchemaExporter = new SoapSchemaExporter (Schemas);\r
+                       \r
+                       new SoapProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);\r
                        \r
-                       TypeStubInfo typeInfo = TypeStubManager.GetTypeStub (type);\r
-                       desc.TargetNamespace = typeInfo.WebServiceNamespace;\r
-                       desc.Name = typeInfo.WebServiceName;\r
+                       if (WSConfig.IsSupported (WSProtocol.HttpGet))\r
+                               new HttpGetProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);\r
                        \r
-                       ImportService (desc, typeInfo, url);\r
+                       if (WSConfig.IsSupported (WSProtocol.HttpPost))\r
+                               new HttpPostProtocolReflector ().Reflect (this, type, url, schemaExporter, soapSchemaExporter);\r
+                               \r
+                       int i=0;\r
+                       while (i < types.Schemas.Count) {\r
+                               if (types.Schemas[i].Items.Count == 0) types.Schemas.RemoveAt (i);\r
+                               else i++;\r
+                       }\r
                        \r
                        if (serviceDescriptions.Count == 1)\r
-                               desc.Types = types;\r
+                               serviceDescriptions[0].Types = types;\r
                        else\r
                        {\r
                                foreach (ServiceDescription d in serviceDescriptions)\r
                                {\r
                                        d.Types = new Types();\r
                                        for (int n=0; n<types.Schemas.Count; n++)\r
-                                               AddImport (d, types.Schemas[n].TargetNamespace, GetSchemaUrl (url, n));\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               Service ImportService (ServiceDescription desc, TypeStubInfo typeInfo, string url)\r
-               {\r
-                       Service service = new Service ();\r
-                       service.Name = typeInfo.WebServiceName;\r
-                       service.Documentation = typeInfo.Description;\r
-\r
-                       desc.Services.Add (service);\r
-                       \r
-                       foreach (BindingInfo binfo in typeInfo.Bindings)\r
-                               ImportBinding (desc, service, typeInfo, url, binfo);\r
-\r
-                       return service;\r
-               }\r
-               \r
-               void ImportBinding (ServiceDescription desc, Service service, TypeStubInfo typeInfo, string url, BindingInfo binfo)\r
-               {\r
-                       Port port = new Port ();\r
-                       port.Name = binfo.Name;\r
-                       port.Binding = new XmlQualifiedName (binfo.Name, binfo.Namespace);\r
-                       service.Ports.Add (port);\r
-\r
-                       SoapAddressBinding abind = new SoapAddressBinding ();\r
-                       abind.Location = url;\r
-                       port.Extensions.Add (abind);\r
-                       \r
-                       if (binfo.Namespace != desc.TargetNamespace)\r
-                       {\r
-                               if (binfo.Location == null || binfo.Location == string.Empty)\r
-                               {\r
-                                       ServiceDescription newDesc = new ServiceDescription();\r
-                                       newDesc.TargetNamespace = binfo.Namespace;\r
-                                       int id = serviceDescriptions.Add (newDesc);\r
-                                       AddImport (desc, binfo.Namespace, GetWsdlUrl (url,id));\r
-                                       ImportBindingContent (newDesc, typeInfo, url, binfo);\r
-                               }\r
-                               else\r
-                                       AddImport (desc, binfo.Namespace, binfo.Location);\r
-                       }\r
-                       else\r
-                               ImportBindingContent (desc, typeInfo, url, binfo);\r
-               }\r
-               \r
-               void ImportBindingContent (ServiceDescription desc, TypeStubInfo typeInfo, string url, BindingInfo binfo)\r
-               {\r
-                       Binding binding = new Binding ();\r
-                       binding.Name = binfo.Name;\r
-                       binding.Type = new XmlQualifiedName (binfo.Name, binfo.Namespace);\r
-                       desc.Bindings.Add (binding);\r
-                       \r
-                       SoapBinding sb = new SoapBinding ();\r
-                       sb.Transport = SoapBinding.HttpTransport;\r
-                       sb.Style = typeInfo.SoapBindingStyle;\r
-                       binding.Extensions.Add (sb);\r
-                       \r
-                       PortType ptype = new PortType ();\r
-                       ptype.Name = binding.Name;\r
-                       desc.PortTypes.Add (ptype);\r
-\r
-                       foreach (MethodStubInfo method in typeInfo.Methods)\r
-                       {\r
-                               if (method.Binding != binding.Name) continue;\r
-                               \r
-                               Operation oper = ImportOperation (desc, method);\r
-                               ptype.Operations.Add (oper);\r
-\r
-                               OperationBinding operb = ImportOperationBinding (desc, method);\r
-                               binding.Operations.Add (operb);\r
-                       }\r
-               }\r
-               \r
-               Operation ImportOperation (ServiceDescription desc, MethodStubInfo method)\r
-               {\r
-                       Operation oper = new Operation ();\r
-                       oper.Name = method.Name;\r
-                       oper.Documentation = method.Description;\r
-                       \r
-                       OperationInput inOp = new OperationInput ();\r
-                       inOp.Message = ImportMessage (desc, oper.Name + "In", method.InputMembersMapping, method);\r
-                       oper.Messages.Add (inOp);\r
-                       \r
-                       OperationOutput outOp = new OperationOutput ();\r
-                       outOp.Message = ImportMessage (desc, oper.Name + "Out", method.OutputMembersMapping, method);\r
-                       oper.Messages.Add (outOp);\r
-                       \r
-                       return oper;\r
-               }\r
-               \r
-               OperationBinding ImportOperationBinding (ServiceDescription desc, MethodStubInfo method)\r
-               {\r
-                       OperationBinding oper = new OperationBinding ();\r
-                       oper.Name = method.Name;\r
-                       \r
-                       SoapOperationBinding sob = new SoapOperationBinding();\r
-                       sob.SoapAction = method.Action;\r
-                       sob.Style = method.SoapBindingStyle;\r
-                       oper.Extensions.Add (sob);\r
-                       \r
-                       InputBinding inOp = new InputBinding ();\r
-                       AddOperationMsgBindings (desc, inOp, method);\r
-                       oper.Input = inOp;\r
-                       \r
-                       OutputBinding outOp = new OutputBinding ();\r
-                       AddOperationMsgBindings (desc, outOp, method);\r
-                       oper.Output = outOp;\r
-                       \r
-                       return oper;\r
-               }\r
-               \r
-               void AddOperationMsgBindings (ServiceDescription desc, MessageBinding msg, MethodStubInfo method)\r
-               {\r
-                       SoapBodyBinding sbbo = new SoapBodyBinding();\r
-                       msg.Extensions.Add (sbbo);\r
-                       sbbo.Use = method.Use;\r
-                       if (method.Use == SoapBindingUse.Encoded)\r
-                       {\r
-                               sbbo.Namespace = desc.TargetNamespace;\r
-                               sbbo.Encoding = "http://schemas.xmlsoap.org/soap/encoding/";\r
-                       }\r
-               }\r
-               \r
-               XmlQualifiedName ImportMessage (ServiceDescription desc, string name, XmlMembersMapping members, MethodStubInfo method)\r
-               {\r
-                       Message msg = new Message ();\r
-                       msg.Name = name;\r
-                       \r
-                       if (method.ParameterStyle == SoapParameterStyle.Wrapped)\r
-                       {\r
-                               MessagePart part = new MessagePart ();\r
-                               part.Name = "parameters";\r
-                               XmlQualifiedName qname = new XmlQualifiedName (members.ElementName, members.Namespace);\r
-                               if (method.Use == SoapBindingUse.Literal) part.Element = qname;\r
-                               else part.Type = qname;\r
-                               msg.Parts.Add (part);\r
-                       }\r
-                       else\r
-                       {\r
-                               for (int n=0; n<members.Count; n++)\r
-                               {\r
-                                       MessagePart part = new MessagePart ();\r
-                                       part.Name = members[n].MemberName;\r
-                                       XmlQualifiedName qname = new XmlQualifiedName (members.ElementName, members.Namespace);\r
-                                       if (method.Use == SoapBindingUse.Literal) part.Element = qname;\r
-                                       else part.Type = qname;\r
-                                       msg.Parts.Add (part);\r
+                                               ProtocolReflector.AddImport (d, types.Schemas[n].TargetNamespace, GetSchemaUrl (url, n));\r
                                }\r
                        }\r
-                       \r
-                       desc.Messages.Add (msg);\r
-                       \r
-                       if (method.Use == SoapBindingUse.Literal)\r
-                               schemaExporter.ExportMembersMapping (members);\r
-                       else\r
-                               soapSchemaExporter.ExportMembersMapping (members);\r
-                       \r
-                       return new XmlQualifiedName (name, members.Namespace);\r
-               }\r
-\r
-               void AddImport (ServiceDescription desc, string ns, string location)\r
-               {\r
-                       Import im = new Import();\r
-                       im.Namespace = ns;\r
-                       im.Location = location;\r
-                       desc.Imports.Add (im);\r
-               }\r
-               \r
-               string GetWsdlUrl (string baseUrl, int id)\r
-               {\r
-                       return baseUrl + "?wsdl=" + id;\r
                }\r
                \r
                string GetSchemaUrl (string baseUrl, int id)\r
@@ -252,6 +104,7 @@ namespace System.Web.Services.Description {
                        return baseUrl + "?schema=" + id;\r
                }\r
                \r
+               \r
                #endregion\r
        }\r
 }