如何在C#中读取SVCLOG文件

时间:2018-11-08 17:13:24

标签: c# xml wcf streamreader

我需要使用服务跟踪查看器找到标签 if convert == 'true': pdf_name = "temp.pdf" pdf_path = os.path.join(settings.BASE_DIR, 'assets/' + pdf_name) image_path = os.path.join(settings.BASE_DIR, 'assets/images') handle_uploaded_file(request.FILES['file'], pdf_path) pdf2jpg.convert_pdf2jpg(pdf_path, image_path, pages="ALL") os.chdir(image_path + "/" + pdf_name) converted_image = image_path + "/" + pdf_name + "/" + glob.glob("*.pdf.jpg")[0] image_file = open(converted_image, 'rb') saved_img = CCFile.objects.create( file=File(image_file), uuid=uuid.uuid4(), name=request.FILES['file'].name + "_converted", modified_by=request.user.username, media_type=".jpg", size=File(image_file).size, additional_info='converted image file', type='Image' ) saved_file = cc_file_serializer.save(modified_by=request.user.username) return Response({ "converted_img": saved_img.as_json(), "saved_file": saved_file.as_json() }, status=status.HTTP_201_CREATED) ,看起来像这样!

<ns2:Response>400 or 200 etc</n2:Response>

或者还有另一种不用使用XML阅读器(阅读所有文档)或在这种情况下使用文本阅读器(我正在重新设计使用<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-14799"> <ns2:SendInvoice xmlns:ns2="http://www.zadrwan.com/services/" xmlns:ns3="http://www.zadrwan.com/services/DocumentSendTo" xmlns:ns4="http://www.zadrwan.com/services/VersionRequest"> <ns2:Response>200</ns2:Response> <ns2:Comments>Success!.</ns2:Comments> </ns2:SendInvoice> </SOAP-ENV:Body> 的VB项目)来获取变量的方法。 ?

1 个答案:

答案 0 :(得分:1)

有很多方法。由于有一个架构,您可以使用xsd.exe工具获取类,因此我将在下面使用代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {

            XmlReader reader = XmlReader.Create(FILENAME);

            XmlSerializer serializer = new XmlSerializer(typeof(TimestampType));
            TimestampType timeStamp = (TimestampType)serializer.Deserialize(reader);
        }
    }
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:2.0.50727.6421
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    // 
    // This source code was auto-generated by xsd, Version=2.0.50727.3038.
    // 


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
        "d")]
    [System.Xml.Serialization.XmlRootAttribute("Timestamp", Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
        "d", IsNullable=false)]
    public partial class TimestampType {

        private AttributedDateTime createdField;

        private AttributedDateTime expiresField;

        private System.Xml.XmlElement[] itemsField;

        private string idField;

        private System.Xml.XmlAttribute[] anyAttrField;

        /// <remarks/>
        public AttributedDateTime Created {
            get {
                return this.createdField;
            }
            set {
                this.createdField = value;
            }
        }

        /// <remarks/>
        public AttributedDateTime Expires {
            get {
                return this.expiresField;
            }
            set {
                this.expiresField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAnyElementAttribute()]
        public System.Xml.XmlElement[] Items {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType="ID")]
        public string Id {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Xml.XmlAttribute[] AnyAttr {
            get {
                return this.anyAttrField;
            }
            set {
                this.anyAttrField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
        "d")]
    [System.Xml.Serialization.XmlRootAttribute("Expires", Namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xs" +
        "d", IsNullable=false)]
    public partial class AttributedDateTime {

        private string idField;

        private System.Xml.XmlAttribute[] anyAttrField;

        private string valueField;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType="ID")]
        public string Id {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Xml.XmlAttribute[] AnyAttr {
            get {
                return this.anyAttrField;
            }
            set {
                this.anyAttrField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTextAttribute()]
        public string Value {
            get {
                return this.valueField;
            }
            set {
                this.valueField = value;
            }
        }
    }


}