示例#1
0
        void FindDataTypes(Type t, Type containerType, Hashtable types, ArrayList services)
        {
            if (IsSystemType(t))
            {
                string ns = GetXmlNamespace(t, null);
                types [ns] = null;
                return;
            }

            if (!IsService(t))
            {
                if (!t.IsSerializable)
                {
                    return;
                }

                string     ns    = GetXmlNamespace(t, containerType);
                SchemaInfo sinfo = (SchemaInfo)types [ns];
                if (sinfo == null)
                {
                    sinfo      = new SchemaInfo();
                    types [ns] = sinfo;
                }

                if (sinfo.Types.Contains(t))
                {
                    return;
                }

                sinfo.Types.Add(t);
                if (t.IsArray)
                {
                    return;
                }

                FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (FieldInfo fi in fields)
                {
                    string fns = GetXmlNamespace(fi.FieldType, t);
                    if (!sinfo.Imports.Contains(fns))
                    {
                        sinfo.Imports.Add(fns);
                    }
                    FindDataTypes(fi.FieldType, t, types, services);
                }
            }
            else
            {
                if (services.Contains(t))
                {
                    return;
                }
                services.Add(t);

                foreach (MethodInfo met in t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    ParameterInfo[] pars = met.GetParameters();
                    foreach (ParameterInfo par in pars)
                    {
                        FindDataTypes(par.ParameterType, t, types, services);
                    }

                    FindDataTypes(met.ReturnType, t, types, services);
                }
            }
        }
示例#2
0
        void WriteServiceBinding(XmlTextWriter tw, ServiceType st, Hashtable dataTypes)
        {
            Type   type     = st.ObjectType;
            string typeName = type.Name;

            MethodInfo[] mets      = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            bool         isService = IsService(type);

            // Messages

            if (isService)
            {
                foreach (MethodInfo met in mets)
                {
                    if (met.DeclaringType.Assembly == typeof(object).Assembly)
                    {
                        continue;
                    }

                    ParameterInfo[] pars = met.GetParameters();
                    tw.WriteStartElement("message", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", typeName + "." + met.Name + "Input");
                    foreach (ParameterInfo par in pars)
                    {
                        if (!par.ParameterType.IsByRef)
                        {
                            WritePart(tw, par.Name, par.ParameterType, type);
                        }
                    }
                    tw.WriteEndElement();                       // message

                    tw.WriteStartElement("message", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", typeName + "." + met.Name + "Output");

                    if (met.ReturnType != typeof(void))
                    {
                        WritePart(tw, "return", met.ReturnType, type);
                    }

                    foreach (ParameterInfo par in pars)
                    {
                        if (par.ParameterType.IsByRef || par.IsOut)
                        {
                            WritePart(tw, par.Name, par.ParameterType, type);
                        }
                    }
                    tw.WriteEndElement();                       // message
                }
            }

            // Port type

            tw.WriteStartElement("portType", MetaData.WsdlNamespace);
            tw.WriteAttributeString("name", typeName + "PortType");

            if (isService)
            {
                foreach (MethodInfo met in mets)
                {
                    if (met.DeclaringType.Assembly == typeof(object).Assembly)
                    {
                        continue;
                    }

                    tw.WriteStartElement("operation", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", met.Name);

                    StringBuilder   sb   = new StringBuilder();
                    ParameterInfo[] pars = met.GetParameters();
                    foreach (ParameterInfo par in pars)
                    {
                        if (sb.Length != 0)
                        {
                            sb.Append(" ");
                        }
                        sb.Append(par.Name);
                    }
                    tw.WriteAttributeString("parameterOrder", sb.ToString());

                    tw.WriteStartElement("input", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", met.Name + "Request");
                    tw.WriteAttributeString("message", "tns:" + typeName + "." + met.Name + "Input");
                    tw.WriteEndElement();

                    tw.WriteStartElement("output", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", met.Name + "Response");
                    tw.WriteAttributeString("message", "tns:" + typeName + "." + met.Name + "Output");
                    tw.WriteEndElement();

                    tw.WriteEndElement();                       // operation
                }
            }
            tw.WriteEndElement();               // portType

            // Binding

            tw.WriteStartElement("binding", MetaData.WsdlNamespace);
            tw.WriteAttributeString("name", typeName + "Binding");
            tw.WriteAttributeString("type", "tns:" + typeName + "PortType");

            tw.WriteStartElement("soap", "binding", MetaData.SoapNamespace);
            tw.WriteAttributeString("style", "rpc");
            tw.WriteAttributeString("transport", "http://schemas.xmlsoap.org/soap/http");
            tw.WriteEndElement();

            WriteTypeSuds(tw, type);

            SchemaInfo sinfo = (SchemaInfo)dataTypes [GetXmlNamespace(type, null)];

            if (sinfo != null && !sinfo.SudsGenerated)
            {
                foreach (Type dt in sinfo.Types)
                {
                    WriteTypeSuds(tw, dt);
                }
                sinfo.SudsGenerated = true;
            }

            if (isService)
            {
                foreach (MethodInfo met in mets)
                {
                    if (met.DeclaringType.Assembly == typeof(object).Assembly)
                    {
                        continue;
                    }

                    tw.WriteStartElement("operation", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", met.Name);

                    tw.WriteStartElement("soap", "operation", MetaData.SoapNamespace);
                    tw.WriteAttributeString("soapAction", GetSoapAction(met));
                    tw.WriteEndElement();

                    tw.WriteStartElement("suds", "method", MetaData.SudsNamespace);
                    tw.WriteAttributeString("attributes", "public");
                    tw.WriteEndElement();

                    tw.WriteStartElement("input", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", met.Name + "Request");
                    WriteMessageBindingBody(tw, type);
                    tw.WriteEndElement();

                    tw.WriteStartElement("output", MetaData.WsdlNamespace);
                    tw.WriteAttributeString("name", met.Name + "Response");
                    WriteMessageBindingBody(tw, type);
                    tw.WriteEndElement();

                    tw.WriteEndElement();                       // operation
                }
            }
            tw.WriteEndElement();               // binding
        }
示例#3
0
        public void ExportTypes(ServiceType[] servicetypes, SdlType sdltype, XmlTextWriter tw)
        {
            if (sdltype == SdlType.Sdl)                 // Obsolete, we don't support this
            {
                throw new NotSupportedException();
            }

            if (servicetypes.Length == 0)
            {
                return;
            }
            Type maint = servicetypes [0].ObjectType;

            Hashtable dataTypes = new Hashtable();
            ArrayList services  = new ArrayList();

            FindTypes(servicetypes, dataTypes, services);

            if (services.Count > 0)
            {
                maint = ((ServiceType)services[0]).ObjectType;
            }

            string serviceNs = GetXmlNamespace(maint, null);

            tw.Formatting = Formatting.Indented;
            tw.WriteStartElement("definitions", MetaData.WsdlNamespace);
            tw.WriteAttributeString("name", maint.Name);
            tw.WriteAttributeString("targetNamespace", serviceNs);
            tw.WriteAttributeString("xmlns", MetaData.XmlnsNamespace, MetaData.WsdlNamespace);
            tw.WriteAttributeString("xmlns", "tns", MetaData.XmlnsNamespace, serviceNs);
            tw.WriteAttributeString("xmlns", "xsd", MetaData.XmlnsNamespace, MetaData.SchemaNamespace);
            tw.WriteAttributeString("xmlns", "xsi", MetaData.XmlnsNamespace, MetaData.SchemaInstanceNamespace);
            tw.WriteAttributeString("xmlns", "suds", MetaData.XmlnsNamespace, MetaData.SudsNamespace);
            tw.WriteAttributeString("xmlns", "wsdl", MetaData.XmlnsNamespace, MetaData.WsdlNamespace);
            tw.WriteAttributeString("xmlns", "soapenc", MetaData.XmlnsNamespace, MetaData.SoapEncodingNamespace);
            tw.WriteAttributeString("xmlns", "soap", MetaData.XmlnsNamespace, MetaData.SoapNamespace);

            int nums = 0;

            foreach (DictionaryEntry entry in dataTypes)
            {
                string ns = (string)entry.Key;
                if (tw.LookupPrefix(ns) != null)
                {
                    continue;
                }
                tw.WriteAttributeString("xmlns", "ns" + nums, MetaData.XmlnsNamespace, ns);
                nums++;
            }

            // Schema

            if (dataTypes.Count > 0)
            {
                tw.WriteStartElement("types", MetaData.WsdlNamespace);
                foreach (DictionaryEntry entry in dataTypes)
                {
                    SchemaInfo sinfo = (SchemaInfo)entry.Value;
                    if (sinfo == null || sinfo.Types.Count == 0)
                    {
                        continue;
                    }

                    tw.WriteStartElement("s", "schema", MetaData.SchemaNamespace);
                    tw.WriteAttributeString("targetNamespace", (string)entry.Key);
                    tw.WriteAttributeString("elementFormDefault", "unqualified");
                    tw.WriteAttributeString("attributeFormDefault", "unqualified");

                    foreach (string ns in sinfo.Imports)
                    {
                        if (ns == (string)entry.Key)
                        {
                            continue;
                        }
                        tw.WriteStartElement("import", MetaData.SchemaNamespace);
                        tw.WriteAttributeString("namespace", ns);
                        tw.WriteEndElement();
                    }

                    foreach (Type type in sinfo.Types)
                    {
                        WriteDataTypeSchema(tw, type);
                    }

                    tw.WriteEndElement();
                }
                tw.WriteEndElement();
            }

            // Bindings

/*			foreach (ServiceType st in servicetypes)
 *                              WriteServiceBinding (tw, st);
 */
            foreach (ServiceType st in services)
            {
                WriteServiceBinding(tw, st, dataTypes);
            }

            // Service element

            tw.WriteStartElement("service", MetaData.WsdlNamespace);
            if (services.Count > 0)
            {
                tw.WriteAttributeString("name", GetServiceName(maint));
            }
            else
            {
                tw.WriteAttributeString("name", "Service");
            }

            foreach (ServiceType st in services)
            {
                WriteServiceType(tw, st);
            }
            tw.WriteEndElement();

            // Closing

            tw.WriteEndElement();
            tw.Flush();
        }
示例#4
0
		void FindDataTypes (Type t, Type containerType, Hashtable types, ArrayList services)
		{
			if (IsSystemType (t))
			{
				string ns = GetXmlNamespace (t, null);
				types [ns] = null;
				return;
			}
			
			if (!IsService (t))
			{
				if (!t.IsSerializable) return;
				
				string ns = GetXmlNamespace (t, containerType);
				SchemaInfo sinfo = (SchemaInfo) types [ns];
				if (sinfo == null)
				{
					sinfo = new SchemaInfo ();
					types [ns] = sinfo;
				}
				
				if (sinfo.Types.Contains (t)) return;
				
				sinfo.Types.Add (t);
				if (t.IsArray) return;
				
				FieldInfo[] fields = t.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
				foreach (FieldInfo fi in fields)
				{
					string fns = GetXmlNamespace (fi.FieldType, t);
					if (!sinfo.Imports.Contains (fns)) sinfo.Imports.Add (fns);
					FindDataTypes (fi.FieldType, t, types, services);
				}
			}
			else
			{
				if (services.Contains (t)) return;
				services.Add (t);
				
				foreach (MethodInfo met in t.GetMethods (BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
				{
					ParameterInfo[] pars = met.GetParameters ();
					foreach (ParameterInfo par in pars)
						FindDataTypes (par.ParameterType, t, types, services);
							
					FindDataTypes (met.ReturnType, t, types, services);
				}
			}
		}