示例#1
0
        public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            XmlObjectElement mainElement = null;

            var envelope = new SoapXmlEnvelope()
            {
                Body = new SoapXmlBody()
                {
                    Data = context.Object
                }
            };
            await context.HttpContext.Response.WriteAsync(await Xml.Serialize(envelope, xmlPrefix, typeCollections, (obj, args) =>
            {
                var element = args.Element;

                if (obj == context.Object)
                {
                    element.Prefix = xmlPrefix.Local;
                    element.Name   = obj.GetType().Name;
                    mainElement    = element;
                }
                else if (mainElement != null && element.IsDescendantOf(mainElement))
                {
                    element.Prefix = xmlPrefix.Local;
                }
            }));
        }
示例#2
0
文件: Xml.cs 项目: 4vz/Aveezo
 public bool IsDescendantOf(XmlObjectElement element)
 {
     if (element == null)
     {
         return(false);
     }
     else if (this == element)
     {
         return(true);
     }
     else if (Parent == null)
     {
         return(false);
     }
     else
     {
         return(Parent.IsDescendantOf(element));
     }
 }
示例#3
0
        public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            var httpContext = context.HttpContext;
            var response    = httpContext.Response;
            var request     = httpContext.Request;

            var soapxml = httpContext.Items["soapxml"] as string;

            var rest        = context.HttpContext.Request.Path.ToString().ToLower();
            var service     = ""; // $"http://{context.HttpContext.Request.Host}{Rest.SoapXmlPrefix}{rest}";
            var serviceWsdl = ""; // $"http://{context.HttpContext.Request.Host}{Rest.SoapXmlPrefix}{Rest.WsdlXmlPrefix}{rest}";
            var data        = context.Object;

            string interfaceName = "interface";
            string bindingName   = "binding";
            string serviceName   = "service";
            string endpointName  = "endpoint";

            var wsdl = new WsdlXmlDescription(serviceWsdl, service)
            {
                Documentation = "Afis Herman Reza Devara",
                Types         = new WsdlXmlTypes {
                    Schema = data
                },
                Interface = new WsdlXmlInterface(interfaceName),
                Binding   = new WsdlXmlBinding(interfaceName, bindingName),
                Service   = new WsdlXmlService(interfaceName, serviceName)
                {
                    Endpoint = new WsdlXmlEndpoint(endpointName, bindingName, service)
                }
            };

            XmlObjectElement dataElement = null;

            var responseBody = await Xml.Serialize(wsdl, xmlPrefix, typeCollections, (obj, args) =>
            {
                var element = args.Element;

                if (element.Property != null && element.Property.Name == "Documentation")
                {
                    element.Name = "documentation";
                }
                else if (obj == data)
                {
                    dataElement = element;

                    element.Name     = "schema";
                    element.Options |= XmlObjectAttributeOptions.XmlSchema;

                    Xml.AddBuiltInSchemaElements(element);
                    Xml.AddTargetNamespace(element, service);
                }
                else if (dataElement != null && element.IsDescendantOf(dataElement))
                {
                    element.Options |= XmlObjectAttributeOptions.XmlSchemaElement;

                    if (element.IsSerialized)
                    {
                        element.SchemaName = XmlObjectSchemaName.ComplexType;
                        element.Add(XmlObjectSchemaElement.Sequence);
                        element.SchemaGroup = XmlObjectSchemaElement.Sequence;
                    }
                    else
                    {
                        element.SchemaName  = XmlObjectSchemaName.Element;
                        element.SchemaGroup = XmlObjectSchemaElement.Sequence;
                    }
                }
            });

            await response.WriteAsync($"{responseBody}");
        }