我正试图在我的工作中构建c#软件,该软件可以从具有tr-069(CWMP)的设备中获取信息。有人能告诉我怎么再建这个吗?还有人能告诉我如何从CPE中获取soap消息吗?
我已经做好了。第一个函数只适用于soap。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace SoapToClassData
{
class Program
{
static void Main(string[] args)
{
Execute();
}
public static void Execute()
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
// soap
soapEnvelopeXml.LoadXml(@"<?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: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>DrayTek Corp.</Manufacturer>
<OUI>00507F</OUI>
<ProductClass>EG8040H5</ProductClass>
<SerialNumber>001DAA18E148</SerialNumber>
</DeviceId>
<Event SOAP-ENC:arrayType=""cwmp: EventStruct[04]"">
<EventStruct>
<EventCode>0 BOOTSTRAP</EventCode>
<CommandKey></CommandKey>
</EventStruct>
<EventStruct>
<EventCode>1 BOOT</EventCode>
<CommandKey></CommandKey>
</EventStruct>
<EventStruct>
<EventCode>2 PERIODIC</EventCode>
<CommandKey></CommandKey>
</EventStruct>
<EventStruct>
<EventCode>4 VALUE CHANGE</EventCode>
<CommandKey></CommandKey>
</EventStruct>
</Event>
<MaxEnvelopes>1</MaxEnvelopes>
<CurrentTime>2020-02-17T14:30:33+00:00</CurrentTime>
<RetryCount>0</RetryCount>
<ParameterList SOAP-ENC:arrayType=""cwmp:ParameterValueStruct[9]"">
<ParameterValueStruct>
<Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>
<Value xsi:type=""xsd:string""/>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>
<Value xsi:type=""xsd:string"">http://ip:8069/cwm/CRN.html</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.SerialNumber</Name>
<Value xsi:type=""xsd:string"">001DAA18E148</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"">e</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>
<Value xsi:type=""xsd:string"">3.9.1.1</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"">213.125.61.108</Value>
</ParameterValueStruct>
</ParameterList>
</cwmp:Inform>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>CWMP fault</faultstring>
<detail>
<cwmp:fault>
<FaultCode>9005</FaultCode>
<FaultString>Invalid parameter Name</FaultString>
</cwmp:fault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
// I get here the soap that i've typed here above
Console.WriteLine(soapResult);
}
}
}
在这里,我与acs建立连接并发送soap。
// connection with the acs
public static HttpWebRequest CreateWebRequest()
{
string action = "https://acsnoc.hompes.nl:443/ACSServer/services/ACSServlet";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://acsnoc.hompes.nl:443/ACSServer/services/ACSServlet");
webRequest.Credentials = new NetworkCredential("username", "password");
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
}
}
发布于 2020-07-23 23:21:50
您需要更好地理解协议,我建议您在这里花费一些时间,https://www.qacafe.com/tr-069-training/session-overview/,它们有关于这个主题的很好的材料。
至于你的密码..。你看完训练后会明白,如果你想和CPE谈谈.你不能..。不是直接的。
可以这么说,协议有点颠倒。通信是始终启动的 CPE。您想要与CPE对话,使用正确的凭据,您可以执行一个“连接请求”,该请求只有一个HTTP请求。你可以把这看成是“戳”..。“嘿,我要和你谈谈”。但是,它不会与“您”对话,它将与配置好的ACS对话。
通信从CPE发送一个“通知”开始,它基本上类似于作为SOAP请求发送的XML块。
在一些“异教徒式”的响应和请求之后,CPE将发送和“空帖子”(一个没有任何有效载荷的帖子请求.(除了头)。这是在告诉ACS“我在等指示”。
再一次,就像前面说的,协议有点颠倒,我的意思是.
来自ACS的“请求”(不管是用于读取或设置信息),它们一个接一个地进入HTTP响应正文中的CPE,从第一个空帖子开始。然后CPE用另一个帖子来响应第一个请求的数据,ACS在HTTP响应中发送下一个“请求”.诸若此类。
当ACS没有什么可说的时候,它将响应他最后收到的帖子,用‘HTTP 204 No内容’这样告诉CPE“我没有什么可说的了”,所以CPE关闭了HTTP会话。
红色箭头是从CPE发送的HTTP请求。绿色箭头是对这些请求的HTTP响应。
https://stackoverflow.com/questions/60305929
复制相似问题