Как проанализировать файл формата данных SOAP с помощью C # - PullRequest
0 голосов
/ 11 июля 2019

У меня есть файл ACS-test.log, это данные в формате SOAP.Как показано ниже:

15:32:14.186 [http-nio-18080-exec-5] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void com.inspur.tr069.TR069Controller.tr069(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"> <SOAP-ENV:Header> <cwmp:ID SOAP-ENV:mustUnderstand="1">279384</cwmp:ID> </SOAP-ENV:Header> <SOAP-ENV:Body> <cwmp:Inform> <DeviceId> <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer> <OUI>00259E</OUI> <ProductClass>EG8040H5</ProductClass> <SerialNumber>48575443FF5E5D9D</SerialNumber> </DeviceId> <Event SOAP-ENC:arrayType="cwmp:EventStruct[1]"> <EventStruct> <EventCode>2 PERIODIC</EventCode> <CommandKey/> </EventStruct> </Event> <MaxEnvelopes>1</MaxEnvelopes> <CurrentTime>2019-06-19T15:30:33+00:00</CurrentTime> <RetryCount>0</RetryCount> <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[8]"> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name> <Value xsi:type="xsd:string">http://10.240.12.35:7547/1d9564b694ef18090a9377cd6f3217eb</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceSummary</Name> <Value xsi:type="xsd:string">InternetGatewayDevice:1.4[](Baseline:1, EthernetLAN:1, WiFiLAN:2, Time:1, IPPing:1, DeviceAssociation:1)</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name> <Value xsi:type="xsd:string">1.0</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name> <Value xsi:type="xsd:string">172D.A</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name> <Value xsi:type="xsd:string">V5R019C00S115</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name> <Value xsi:type="xsd:string">10.240.12.35</Value> </ParameterValueStruct> </ParameterList> </cwmp:Inform> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 
1
Inform
ACS ip is 10.240.12.35
ACS Device is Manufacturer:Huawei Technologies Co., Ltd OUI:00259E productClass:EG8040H5 SerialNubmer:48575443FF5E5D9D
Write by xml:
    <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><cwmp:ID SOAP-ENV:mustUnderstand="1">279384</cwmp:ID></SOAP-ENV:Header><SOAP-ENV:Body><cwmp:InformResponse><MaxEnvelopes>1</MaxEnvelopes></cwmp:InformResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> ContextLength:525
---------------------------------------------------------------------

15:32:14.190 [http-nio-18080-exec-5] DEBUG org.springframework.web.servlet.DispatcherServlet - Completed 200 OK
15:32:14.200 [http-nio-18080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - POST "/tr069", parameters={}
15:32:14.201 [http-nio-18080-exec-8] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void com.inspur.tr069.TR069Controller.tr069(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
15:32:14.201 [http-nio-18080-exec-8] DEBUG org.springframework.web.servlet.DispatcherServlet - Completed 200 OK
15:32:19.248 [http-nio-18080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - POST "/tr069", parameters={}
15:32:19.249 [http-nio-18080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void com.inspur.tr069.TR069Controller.tr069(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"> <SOAP-ENV:Header> <cwmp:ID SOAP-ENV:mustUnderstand="1">279385</cwmp:ID> </SOAP-ENV:Header> <SOAP-ENV:Body> <cwmp:Inform> <DeviceId> <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer> <OUI>00259E</OUI> <ProductClass>EG8040H5</ProductClass> <SerialNumber>48575443FF5E5D9D</SerialNumber> </DeviceId> <Event SOAP-ENC:arrayType="cwmp:EventStruct[1]"> <EventStruct> <EventCode>2 PERIODIC</EventCode> <CommandKey/> </EventStruct> </Event> <MaxEnvelopes>1</MaxEnvelopes> <CurrentTime>2019-06-19T15:30:38+00:00</CurrentTime> <RetryCount>0</RetryCount> <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[8]"> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name> <Value xsi:type="xsd:string">http://10.240.12.35:7547/1d9564b694ef18090a9377cd6f3217eb</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceSummary</Name> <Value xsi:type="xsd:string">InternetGatewayDevice:1.4[](Baseline:1, EthernetLAN:1, WiFiLAN:2, Time:1, IPPing:1, DeviceAssociation:1)</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name> <Value xsi:type="xsd:string">1.0</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name> <Value xsi:type="xsd:string">172D.A</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name> <Value xsi:type="xsd:string">V5R019C00S115</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name> <Value xsi:type="xsd:string">10.240.12.35</Value> </ParameterValueStruct> </ParameterList> </cwmp:Inform> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 
1
Inform
ACS ip is 10.240.12.35
ACS Device is Manufacturer:Huawei Technologies Co., Ltd OUI:00259E productClass:EG8040H5 SerialNubmer:48575443FF5E5D9D
Write by xml:
    <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><cwmp:ID SOAP-ENV:mustUnderstand="1">279385</cwmp:ID></SOAP-ENV:Header><SOAP-ENV:Body><cwmp:InformResponse><MaxEnvelopes>1</MaxEnvelopes></cwmp:InformResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> ContextLength:525
---------------------------------------------------------------------

15:32:19.254 [http-nio-18080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Completed 200 OK
15:32:19.265 [http-nio-18080-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - POST "/tr069", parameters={}
15:32:19.266 [http-nio-18080-exec-2] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void com.inspur.tr069.TR069Controller.tr069(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
15:32:19.266 [http-nio-18080-exec-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Completed 200 OK
15:32:24.305 [http-nio-18080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - POST "/tr069", parameters={}
15:32:24.306 [http-nio-18080-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void com.inspur.tr069.TR069Controller.tr069(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"> <SOAP-ENV:Header> <cwmp:ID SOAP-ENV:mustUnderstand="1">279386</cwmp:ID> </SOAP-ENV:Header> <SOAP-ENV:Body> <cwmp:Inform> <DeviceId> <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer> <OUI>00259E</OUI> <ProductClass>EG8040H5</ProductClass> <SerialNumber>48575443FF5E5D9D</SerialNumber> </DeviceId> <Event SOAP-ENC:arrayType="cwmp:EventStruct[1]"> <EventStruct> <EventCode>2 PERIODIC</EventCode> <CommandKey/> </EventStruct> </Event> <MaxEnvelopes>1</MaxEnvelopes> <CurrentTime>2019-06-19T15:30:43+00:00</CurrentTime> <RetryCount>0</RetryCount> <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[8]"> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name> <Value xsi:type="xsd:string">http://10.240.12.35:7547/1d9564b694ef18090a9377cd6f3217eb</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceSummary</Name> <Value xsi:type="xsd:string">InternetGatewayDevice:1.4[](Baseline:1, EthernetLAN:1, WiFiLAN:2, Time:1, IPPing:1, DeviceAssociation:1)</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name> <Value xsi:type="xsd:string">1.0</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name> <Value xsi:type="xsd:string">172D.A</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name> <Value xsi:type="xsd:string">V5R019C00S115</Value> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name> <Value xsi:type="xsd:string"/> </ParameterValueStruct> <ParameterValueStruct> <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name> <Value xsi:type="xsd:string">10.240.12.35</Value> </ParameterValueStruct> </ParameterList> </cwmp:Inform> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

Я хочу получить эти данные:

org.springframework.web.servlet.DispatcherServlet - Completed 200 OK
org.springframework.web.servlet.DispatcherServlet - POST "/tr069", parameters={}
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void 
org.springframework.web.servlet.DispatcherServlet - Completed 200 OK
org.springframework.web.servlet.DispatcherServlet - POST "/tr069", parameters={}
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to public void 

Я вижу, что есть какой-то ответ, такой как Анализ сообщения SOAP для классов c # , но ихФормат SOAP отличается, поэтому он не может мне помочь.

Может кто-нибудь сказать мне, как я могу преобразовать этот файл SOAP?

1 Ответ

1 голос
/ 12 июля 2019

Использование Regex:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.txt";
        static void Main(string[] args)
        {
            //15:32:14.186 [http-nio-18080-exec-5] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
            string pattern = @"(?'time'[\d:.]+)\s+\[(?'http'[^]]+)\]\s+DEBUG\s+(?'message'.*)";
            StreamReader reader = new StreamReader(FILENAME);
            string line = "";
            while((line = reader.ReadLine()) != null)
            {
                Match match = Regex.Match(line, pattern);
                if (match.Success)
                {
                    Console.WriteLine(match.Groups["message"].Value);
                }
            }
            Console.ReadLine();
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...