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)); }
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!"); }