title: ONVIF PullPointSubscriptionClient.PullMessages
body: <p>I'm trying to get event messages from some ONVIF devices. My code is in C#.</p>
  
  <p>On a (Axis camera) device on <code>EventPortTypeClient.CreatePullPointSubscription</code> returns:</p>
  
  <pre><code>Address.Value: http : / /192.168.8.48/onvif/services
  ReferenceParameters.Any.First().OuterXml: &lt;dom0:SubscriptionId xmlns:dom0="http : / /www.axis.com/2009/event"&gt;38&lt;/dom0:SubscriptionId&gt;
  </code></pre>
  
  <p>So I add the <strong>"To"</strong> and <strong>"SubscriptionId"</strong> soap headers and can get event messages with <code>PullPointSubscriptionClient.PullMessages("PT5M", 99, Any, out CurrentTime, out NotificationMessages)</code></p>
  
  <pre><code>&lt;s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;s:Header&gt;
      &lt;a:Action s:mustUnderstand="1"&gt;http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest&lt;/a:Action&gt;
      &lt;a:MessageID&gt;urn:uuid:f243dbe4-b082-4a6c-aa65-8145468fcf3e&lt;/a:MessageID&gt;
      &lt;a:ReplyTo&gt;
        &lt;a:Address&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/a:Address&gt;
      &lt;/a:ReplyTo&gt;
      &lt;VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink"&gt;uIDPo0zfnhoyh15KqPZwP/IS9H0AAAAAdCoo8EjbCUScx/bG/DGcdXp8kY6WrAJDp0TTtNAtj0EACQAA&lt;/VsDebuggerCausalityData&gt;
      &lt;Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
        &lt;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="&gt;
          &lt;wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;root&lt;/wsse:Username&gt;
          &lt;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"&gt;pjwOOO0hOXtUZyJb6B6Lb0ctRIU=&lt;/wsse:Password&gt;
          &lt;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"&gt;DEE/P1c/P1E/eG9XTT87Pz8/&lt;/wsse:Nonce&gt;
          &lt;wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;2015-03-02T19:06:54.269Z&lt;/wsu:Created&gt;
        &lt;/wsse:UsernameToken&gt;
      &lt;/Security&gt;
      &lt;a:To s:mustUnderstand="1"&gt;http://192.168.8.48/onvif/services&lt;/a:To&gt;
      &lt;SubscriptionId s:mustUnderstand="1" xmlns="http://www.axis.com/2009/event"&gt;38&lt;/SubscriptionId&gt;
    &lt;/s:Header&gt;
    &lt;s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl"&gt;
        &lt;Timeout&gt;PT5M&lt;/Timeout&gt;
        &lt;MessageLimit&gt;99&lt;/MessageLimit&gt;
      &lt;/PullMessages&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>But with devices that only return Address.Value's like:</p>
  
  <ul>
  <li>(DAHUA) Address.Value: 
  <code>http : / /192.168.8.243/onvif/Subscription?Idx=57</code></li>
  <li>(Siqura) Address.Value:<br>
  <code>http : / /192.168.8.14/onvif/events_service/SubscriptionManager/15000</code></li>
  </ul>
  
  <p>I add only the <strong>"To"</strong> soap header, but the <code>PullPointSubscriptionClient.PullMessages("PT5M", 99, Any, out CurrentTime, out NotificationMessages)</code> method gives a fault error.</p>
  
  <pre><code>&lt;s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;s:Header&gt;
      &lt;a:Action s:mustUnderstand="1"&gt;http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest&lt;/a:Action&gt;
      &lt;a:MessageID&gt;urn:uuid:9e28fea7-541f-450e-8ad0-01a210f76aa9&lt;/a:MessageID&gt;
      &lt;a:ReplyTo&gt;
        &lt;a:Address&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/a:Address&gt;
      &lt;/a:ReplyTo&gt;
      &lt;VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink"&gt;uIDPozBB+X6a8MJEsKScTDAWhKsAAAAAJ3lo8k+wp0CaILCjmW72gQ39eqv52SBMteWBucAF600ACQAA&lt;/VsDebuggerCausalityData&gt;
      &lt;Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
        &lt;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="&gt;
          &lt;wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;admin&lt;/wsse:Username&gt;
          &lt;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"&gt;o3Nrz8F+V7kLjMunS/JBQKhu5xg=&lt;/wsse:Password&gt;
          &lt;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"&gt;PxtFP2k/Pz8/P2g/Pz8/Bz8=&lt;/wsse:Nonce&gt;
          &lt;wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;2015-03-02T19:03:36.894Z&lt;/wsu:Created&gt;
        &lt;/wsse:UsernameToken&gt;
      &lt;/Security&gt;
      &lt;a:To s:mustUnderstand="1"&gt;http://192.168.8.243/onvif/Subscription?Idx=57&lt;/a:To&gt;
    &lt;/s:Header&gt;
    &lt;s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;PullMessages xmlns="http://www.onvif.org/ver10/events/wsdl"&gt;
        &lt;Timeout&gt;PT5M&lt;/Timeout&gt;
        &lt;MessageLimit&gt;99&lt;/MessageLimit&gt;
      &lt;/PullMessages&gt;
    &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>Any help on this?</p>
  
  <p><strong>SOLUTION:</strong></p>
  
  <pre><code>System.Xml.XmlElement[] Any = new System.Xml.XmlElement[] { };
  System.DateTime CurrentTime;
  System.Nullable&lt;System.DateTime&gt; TerminationTime;
  List&lt;MessageHeader&gt; lstHeaders = new List&lt;MessageHeader&gt;() { };
  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) &amp;&amp; (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 -&gt; the proxy endpoint address
  // lstHeaders -&gt; 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());
  </code></pre>