Exemple #1
0
        public void TestWsdl()
        {
            // var def = new Definitions("http://vm21297.hv8.ru:10080/httpservice/ws/complex.1cws?wsdl", "default");
            var def = new Definitions(@"D:\temp\Bases1C.wsdl", "default");

            Console.WriteLine("Def has {0} services.", def.Services.Count());
            foreach (var service in def.Services)
            {
                Console.WriteLine("\tService {0} has {1} endpoints", service.Name, service.Endpoints.Count());
                foreach (var endpoint in service.Endpoints)
                {
                    Console.WriteLine("\t\tEndpoint {0} as {1} operations", endpoint.Name, endpoint.Interface.Operations.Count());
                    foreach (var operation in endpoint.Interface.Operations)
                    {
                        Console.WriteLine("\t\t\tOperation {0}", operation.Name);
                    }
                }
            }

            var proxy = Proxy.Constructor(def, "http://xfit.local/1C/Bases1C", "Bases1C", "Bases1CSoap") as Proxy;

            proxy.User = "******";
            var methodIndex = proxy.FindMethod("getBasesList");

            Console.WriteLine($"Method `getBasesList` is {methodIndex}");

            var responseType = proxy.XdtoFactory.Type("http://xfit.local/1C/Bases1C", "getBasesListResponse");

            var xri = new XmlReaderImpl();

            xri.OpenFile(@"D:\temp\testresponse.xml");
            xri.Read();
            xri.Read();
            xri.Read();

            var response = proxy.XdtoFactory.ReadXml(xri, responseType);
        }
Exemple #2
0
        public IValue ReadXML(XmlReaderImpl xmlReader, IValue valueType = null)
        {
            TypeTypeValue typeValue = null;

            if (valueType is TypeTypeValue typeTypeValue)
            {
                typeValue = typeTypeValue;
            }

            else if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Element))
            {
                IValue xsiType = xmlReader.GetAttribute(ValueFactory.Create("type"), XmlSchema.InstanceNamespace);
                IValue xsiNil  = xmlReader.GetAttribute(ValueFactory.Create("nil"), XmlSchema.InstanceNamespace);

                if (xsiType.DataType == DataType.String)
                {
                    switch (xsiType.AsString())
                    {
                    case "string":
                        typeValue = new TypeTypeValue("String");
                        break;

                    case "decimal":
                        typeValue = new TypeTypeValue("Number");
                        break;

                    case "boolean":
                        typeValue = new TypeTypeValue("Boolean");
                        break;

                    case "dateTime":
                        typeValue = new TypeTypeValue("Date");
                        break;

                    default:
                        break;
                    }
                }
                else if (xsiNil.DataType == DataType.String)
                {
                    typeValue = new TypeTypeValue("Undefined");
                }
            }
            ;

            if (typeValue == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            Type implType = TypeManager.GetImplementingClass(typeValue.Value.ID);

            IValue result = ValueFactory.Create();

            if (typeValue.Equals(new TypeTypeValue("Undefined")))
            {
                result = ValueFactory.Create();
                xmlReader.Skip();
            }
            else if (implType == typeof(DataType))
            {
                xmlReader.Read();
                if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Text))
                {
                    result = XMLValue(typeValue, xmlReader.Value);
                    xmlReader.Read();
                }
                else
                {
                    throw RuntimeException.InvalidArgumentValue();
                }
            }
            else if (typeof(IXDTOSerializableXML).IsAssignableFrom(implType))
            {
                result = Activator.CreateInstance(implType, new object[] { xmlReader, this }) as IValue;
            }

            xmlReader.Read();
            return(result);
        }
Exemple #3
0
        public IValue ReadXml(XmlReaderImpl reader, IXdtoType type = null)
        {
            if (reader.MoveToContent() == null)
            {
                // TODO: бросить исключение??
                return(null);
            }
            if (type == null)
            {
                var explicitType = reader.GetAttribute(ValueFactory.Create("type"), XmlNs.xsi);
                if (explicitType.DataType == DataType.Undefined)
                {
                    type = new XdtoObjectType();
                }
                else
                {
                    var defaultNamespace = reader.NamespaceContext.DefaultNamespace;

                    // Задан тип - пытаемся его распознать
                    var sType        = explicitType.AsString();
                    var nameElements = sType.Split(':');

                    var typeUri = nameElements.Count() > 1
                                                                  ? nameElements [0]
                                                                  : defaultNamespace;
                    var typeName = nameElements.Count() > 1
                                                                  ? nameElements [1]
                                                                  : nameElements [0];

                    var nsMapping = reader.NamespaceContext.LookupNamespaceUri(typeUri);
                    if (nsMapping != null && nsMapping.DataType == DataType.String)
                    {
                        typeUri = nsMapping.AsString();
                    }

                    type = this.Type(typeUri, typeName);
                }
            }

            if (type is XdtoObjectType)
            {
                return(ValueFactory.Create(type.Reader.ReadXml(reader, type, this)));
            }

            var xmlNodeTypeEnum = XmlNodeTypeEnum.CreateInstance();
            var xmlElementStart = xmlNodeTypeEnum.FromNativeValue(XmlNodeType.Element);
            var xmlElementEnd   = xmlNodeTypeEnum.FromNativeValue(XmlNodeType.EndElement);

            if (type is XdtoValueType)
            {
                if (reader.NodeType.Equals(xmlElementStart))
                {
                    reader.Read();
                }
                var result = type.Reader.ReadXml(reader, type, this);
                if (!reader.NodeType.Equals(xmlElementEnd))
                {
                    reader.Skip();
                }

                var pd = new PrimitiveValuesSerializer();
                return(pd.DeserializeXdto(result));
            }

            throw new NotSupportedException("Неожиданный тип XDTO!");
        }
Exemple #4
0
        public IParsedResponse ParseResponse(XmlReaderImpl reader, XdtoSerializerImpl serializer)
        {
            var retValue     = ValueFactory.Create();
            var outputParams = new Dictionary <int, IValue> ();

            var xmlNodeTypeEnum = XmlNodeTypeEnum.CreateInstance();
            var xmlElementStart = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.Element);

            if (!reader.Read() ||
                !reader.LocalName.Equals("Envelope") ||
                !reader.NodeType.Equals(xmlElementStart)
                // TODO: перевести XML на простые перечисления
                )
            {
                return(new SoapExceptionResponse("Wrong response!"));
            }

            reader.MoveToContent();

            if (!reader.Read() ||
                !reader.LocalName.Equals("Body") ||
                !reader.NodeType.Equals(xmlElementStart)
                // TODO: перевести XML на простые перечисления
                )
            {
                return(new SoapExceptionResponse("Wrong response!"));
            }

            if (!reader.Read())
            {
                return(new SoapExceptionResponse("Wrong response!"));
            }

            if (reader.LocalName.Equals("Fault") &&
                reader.NodeType.Equals(xmlElementStart))
            {
                reader.Read();
                while (!(reader.LocalName.Equals("faultString") &&
                         reader.NodeType.Equals(xmlElementStart)))
                {
                    if (!reader.Read())
                    {
                        return(new SoapExceptionResponse("Wrong response!"));
                    }
                }
                reader.Read();
                var faultString = reader.Value;
                return(new SoapExceptionResponse(faultString));
            }

            var xdtoResult = serializer.XdtoFactory.ReadXml(reader, ReturnValue.ResponseType ?? ReturnValue.Type) as XdtoDataObject;

            retValue = xdtoResult.Get("return");

            if (retValue is IXdtoValue)
            {
                retValue = serializer.ReadXdto(retValue as IXdtoValue);
            }

            foreach (var param in Parameters)
            {
                if (param.ParameterDirection == ParameterDirectionEnum.In)
                {
                    continue;
                }

                var    argumentIndex = _indexes [param.Name];
                IValue paramValue    = xdtoResult.Get(param.Name);
                if (paramValue is IXdtoValue)
                {
                    paramValue = serializer.ReadXdto(paramValue as IXdtoValue);
                }
                outputParams.Add(argumentIndex, paramValue);
            }

            return(new SuccessfulSoapResponse(retValue, outputParams));
        }
Exemple #5
0
        public IXdtoValue ReadXml(XmlReaderImpl reader, IXdtoType expectedType, XdtoFactory factory)
        {
            // TODO: дублирование кода в трёх ветках

            var result = new XdtoDataObject(this, null, null);

            // TODO: Перевести XML на простые перечисления
            var xmlNodeTypeEnum = XmlNodeTypeEnum.CreateInstance();
            var xmlElementStart = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.Element);
            var xmlText         = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.Text);
            var xmlElementEnd   = xmlNodeTypeEnum.FromNativeValue(System.Xml.XmlNodeType.EndElement);

            while (reader.ReadAttribute())
            {
                if (reader.NamespaceURI.Equals("http://www.w3.org/2000/xmlns/") ||
                    reader.NamespaceURI.Equals(XmlNs.xsi) && reader.LocalName.Equals("type"))
                {
                    continue;
                }
                var propertyName       = reader.LocalName;
                var attributeNamespace = reader.NamespaceURI;
                var attributeProperty  =
                    AllProperties().FirstOrDefault(p => p.Form == XmlFormEnum.Attribute &&
                                                   p.LocalName.Equals(propertyName) &&
                                                   p.NamespaceURI.Equals(attributeNamespace));

                if (attributeProperty == null)
                {
                    if (!Open)
                    {
                        throw new XdtoException($"Ошиба разбора XDTO: Получили неизвестный атрибут {propertyName}");
                    }
                    var type = factory.Type(new XmlDataType("string"));
                    attributeProperty = new XdtoProperty(null, result, XmlFormEnum.Attribute,
                                                         NamespaceUri, propertyName,
                                                         1, -1, type); // TODO: lower / upper для открытого типа
                }

                var attributeValue = attributeProperty.Type.Reader.ReadXml(reader, attributeProperty.Type, factory);
                result.Set(attributeProperty, ValueFactory.Create(attributeValue));
            }

            while (reader.Read())
            {
                if (reader.NodeType.Equals(xmlElementEnd))
                {
                    // TODO: result.Validate()
                    return(result);
                }

                if (reader.NodeType.Equals(xmlText))
                {
                    // надо найти свойство с Form=Text
                    // оно должно быть одно

                    var       textProperty = AllProperties().FirstOrDefault((p) => p.Form == XmlFormEnum.Text);
                    IXdtoType type;
                    IValue    textValue;
                    if (textProperty == null)
                    {
                        if (!Open)
                        {
                            throw new XdtoException($"Ошибка разбора XDTO: Текст {reader.Value} в неположенном месте при разборе типа {this}!");
                        }

                        textProperty = new XdtoProperty(null, result, XmlFormEnum.Text, NamespaceUri, "#text");
                        type         = factory.Type(new XmlDataType("string"));
                        textValue    = ValueFactory.Create(reader.Value);
                    }
                    else
                    {
                        type      = textProperty.Type;
                        textValue = ValueFactory.Create(type.Reader.ReadXml(reader, type, factory));
                    }

                    if (Sequenced)
                    {
                        result.Sequence().Add(textValue.AsString());
                    }
                    else
                    {
                        result.Set(textProperty, textValue);
                    }
                }
                else if (reader.NodeType.Equals(xmlElementStart))
                {
                    var localName = reader.LocalName;
                    var ns        = reader.NamespaceURI;

                    var property = AllProperties().FirstOrDefault((p) => p.LocalName.Equals(localName) &&
                                                                  p.NamespaceURI.Equals(ns) &&
                                                                  p.Form == XmlFormEnum.Element);
                    if (property == null)
                    {
                        if (!Open)
                        {
                            throw new XdtoException($"Ошибка разбора XDTO: Получили неизвестный элемент {localName}");
                        }

                        // TODO: lower / upper для открытого типа
                        property = new XdtoProperty(null, result, XmlFormEnum.Element, ns, localName, 1, 1);
                    }

                    var elementValue = factory.ReadXml(reader, property.Type);

                    // TODO: Разбор anyType
                    if (property.UpperBound != 1)
                    {
                        // TODO: проверка на null - на отсутствие/наличие списка
                        (result.GetList(property) as XdtoList).Add(elementValue);
                    }
                    else
                    {
                        result.Set(property, elementValue);
                    }
                }
            }

            throw new XdtoException("Ошибка разбора XDTO!");
        }