我正在尝试从某些 ONVIF 设备获取事件消息。我的代码是在 C# 中。
在 EventPortTypeClient.CreatePullPointSubscription
上的(Axis 相机)设备上返回:
Address.Value: http : / /192.168.8.48/onvif/services
ReferenceParameters.Any.First().OuterXml: <dom0:SubscriptionId xmlns:dom0="http : / /www.axis.com/2009/event">38</dom0:SubscriptionId>
所以我添加了 "To" 和 "SubscriptionId" 肥皂头,并且可以使用
PullPointSubscriptionClient.PullMessages("PT5M", 99, Any, out CurrentTime, out NotificationMessages)
获取事件消息<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</a:Action>
<a:MessageID>urn:uuid:f243dbe4-b082-4a6c-aa65-8145468fcf3e</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo0zfnhoyh15KqPZwP/IS9H0AAAAAdCoo8EjbCUScx/bG/DGcdXp8kY6WrAJDp0TTtNAtj0EACQAA</VsDebuggerCausalityData>
<Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-GWt5XP2ogUljZ/fzEJvnX0WhGpx3FV4i/dRnE539OFU=">
<wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">root</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">pjwOOO0hOXtUZyJb6B6Lb0ctRIU=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">DEE/P1c/P1E/eG9XTT87Pz8/</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-03-02T19:06:54.269Z</wsu:Created>
</wsse:UsernameToken>
</Security>
<a:To s:mustUnderstand="1">http://192.168.8.48/onvif/services</a:To>
<SubscriptionId s:mustUnderstand="1" xmlns="http://www.axis.com/2009/event">38</SubscriptionId>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl">
<Timeout>PT5M</Timeout>
<MessageLimit>99</MessageLimit>
</PullMessages>
</s:Body>
</s:Envelope>
但是对于只返回 Address.Value 的设备,例如:
http : / /192.168.8.243/onvif/Subscription?Idx=57
http : / /192.168.8.14/onvif/events_service/SubscriptionManager/15000
我只添加了 "To" 肥皂头,但是
PullPointSubscriptionClient.PullMessages("PT5M", 99, Any, out CurrentTime, out NotificationMessages)
方法给出了错误错误。<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</a:Action>
<a:MessageID>urn:uuid:9e28fea7-541f-450e-8ad0-01a210f76aa9</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPozBB+X6a8MJEsKScTDAWhKsAAAAAJ3lo8k+wp0CaILCjmW72gQ39eqv52SBMteWBucAF600ACQAA</VsDebuggerCausalityData>
<Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-IYP/hqttMbWUf7ljIMnByJQv96x2VxajSEnVHBKfLyo=">
<wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">o3Nrz8F+V7kLjMunS/JBQKhu5xg=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">PxtFP2k/Pz8/P2g/Pz8/Bz8=</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-03-02T19:03:36.894Z</wsu:Created>
</wsse:UsernameToken>
</Security>
<a:To s:mustUnderstand="1">http://192.168.8.243/onvif/Subscription?Idx=57</a:To>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl">
<Timeout>PT5M</Timeout>
<MessageLimit>99</MessageLimit>
</PullMessages>
</s:Body>
</s:Envelope>
这有什么帮助吗?
解决方案:
System.Xml.XmlElement[] Any = new System.Xml.XmlElement[] { };
System.DateTime CurrentTime;
System.Nullable<System.DateTime> TerminationTime;
List<MessageHeader> lstHeaders = new List<MessageHeader>() { };
var oEventClient = _session.GetEventPortTypeClient();
var oAux1 = oEventClient.CreatePullPointSubscription(
new onvif10_events.FilterType(),
"PT600S",
new onvif10_events.CreatePullPointSubscriptionSubscriptionPolicy(),
ref Any,
out CurrentTime,
out TerminationTime);
if ((oAux1.ReferenceParameters != null) && (oAux1.ReferenceParameters.Any != null))
{
foreach (System.Xml.XmlElement oXml in oAux1.ReferenceParameters.Any)
{
string strName = oXml.LocalName;
string strNS = oXml.NamespaceURI;
string strValue = oXml.InnerXml;
lstHeaders.Add(MessageHeader.CreateHeader(strName, strNS, strValue, true));
}
}
// oAux1.Address.Value -> the proxy endpoint address
// lstHeaders -> headers to add to the SOAP message of the proxy request
var oPullPointSubscriptionClient = _session.GetPullPointSubscriptionClient(oAux1.Address.Value, lstHeaders);
var oSubscriptionManagerClient = _session.GetSubscriptionManagerClient(oAux1.Address.Value, lstHeaders);
do
{
oPullPointSubscriptionClient.PullMessages("PT60S", 1024, Any, out CurrentTime, out NotificationMessages);
foreach (onvif10_events.NotificationMessageHolderType message in NotificationMessages)
{
/// Handle message
}
var oRenewResult = oSubscriptionManagerClient.Renew(new LIB.Cameras.ONVIF_WS.onvif10_events.Renew() { TerminationTime = "PT600S" });
} while (_session != null);
oSubscriptionManagerClient.Unsubscribe(new onvif10_events.Unsubscribe());
最佳答案
好的。
“TO”标题将被忽略。
PullPointSubscriptionClient 代理端点 URL 是订阅“Address.Value”(而不是“TO”URL)。
关于c# - ONVIF PullPointSubscriptionClient.PullMessages,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28853553/