title: How to call GetChanges() method from SiteData.asmx web service (SharePoint 2010)?
body: <p>I'm trying to run GetChanges method (sitedata.asmx) from a Java application. However I can't figure out the correct parameters I must pass. This is for SharePoint 2010.</p>
  <p>By checking on the <a href="http://download.microsoft.com/download/8/5/8/858F2155-D48D-4C68-9205-29460FD7698F/%5BMS-SITEDATS%5D.PDF" rel="nofollow noreferrer">service protocol specification</a>, I saw this are the required parameters:</p>
  <blockquote>
  <p><strong>objectType:</strong> The change tracking space
  to report about, either
  &quot;ContentDatabase&quot; or &quot;SiteCollection&quot;.
  All other objectType values, as
  defined in section 2.2.5.3, MUST NOT
  be used. Note that &quot;Site&quot; in the
  context of this parameter actually
  means site collection.</p>
  <p><strong>contentDatabaseId:</strong> GUID of the content
  database, known in advance or obtained
  by GetContent request.</p>
  <p><strong>LastChangeId:</strong> A token specifying the starting point
  for the requested change report.
  Normally the protocol client obtains
  this value from the response to a
  previous GetContent or GetChanges operation.</p>
  <p><strong>CurrentChangeId:</strong> A token specifying
  the endpoint for the requested change
  report. If not empty, CurrentChangeId
  must be a valid token obtained from
  the response to a previous GetChanges
  operation. Normally, this element is
  empty; empty specifies that the
  protocol client requests all changes
  starting from the starting point up to
  the present time.</p>
  <p><strong>Timeout:</strong> A value
  that determines how many changes
  should be fetched in the current
  operation. This value MUST be greater
  than 0 and the protocol server MUST
  only fetch x% of total changes that
  are fetched by default, where x is
  (Timeout divided by 30000).</p>
  <p>The protocol client MUST pass tokens that
  correspond to the change tracking
  space specified by the objectType and
  the target URL of the SOAP request.</p>
  </blockquote>
  <p>The SOAP In message I'm sending is as follows:</p>
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;soapenv:Envelope xmlns:soapenv=&quot;http://www.w3.org/2003/05/soap-envelope&quot;&gt;
      &lt;soapenv:Body&gt;
          &lt;ns1:GetChanges xmlns:ns1=&quot;http://schemas.microsoft.com/sharepoint/soap/&quot;&gt;
              &lt;ns1:objectType&gt;SiteCollection&lt;/ns1:objectType&gt;
              &lt;ns1:contentDatabaseId&gt;E5C5E20A-5A9F-406C-B9F6-28923750CECD&lt;/ns1:contentDatabaseId&gt;
              &lt;ns1:startChangeId&gt;1;0;E5C5E20A-5A9F-406C-B9F6-28923750CECD;634438121498470000;46852&lt;/ns1:startChangeId&gt;
              &lt;ns1:Timeout&gt;0&lt;/ns1:Timeout&gt;
          &lt;/ns1:GetChanges&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  <p>However I get this response:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;soap:Envelope xmlns:soap=&quot;http://www.w3.org/2003/05/soap-envelope&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
      &lt;soap:Body&gt;
          &lt;soap:Fault&gt;
              &lt;soap:Code&gt;
                  &lt;soap:Value&gt;soap:Receiver&lt;/soap:Value&gt;
              &lt;/soap:Code&gt;
              &lt;soap:Reason&gt;
                  &lt;soap:Text xml:lang=&quot;en&quot;&gt;Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.&lt;/soap:Text&gt;
              &lt;/soap:Reason&gt;
              &lt;detail&gt;
                  &lt;errorstring xmlns=&quot;http://schemas.microsoft.com/sharepoint/soap/&quot;&gt;Object reference not set to an instance of an object.&lt;/errorstring&gt;
              &lt;/detail&gt;
          &lt;/soap:Fault&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  <p>Checked the logs from SharePoint (located at Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS) and found the following exception:</p>
  <pre><code>SOAP exception: System.NullReferenceException: Object reference not set to an instance of an object.
  at Microsoft.SharePoint.SPChangeToken.ParseChangeToken(String strChangeToken)
  at Microsoft.SharePoint.SPChangeToken..ctor(String strChangeToken)
  at Microsoft.SharePoint.SoapServer.SiteDataImpl.GetChanges(ObjectType objectType, String contentDatabaseId, String&amp; startChangeId, String&amp; endChangeId, Int64 maxChangesToFetch, UInt32 maxSPRequests, Boolean getMetadata, Boolean ignoreSecurityIfInherit, Int32 schemaVersion, Boolean&amp; moreChanges)
  at Microsoft.SharePoint.SoapServer.SiteDataImpl.GetChanges(ObjectType objectType, String contentDatabaseId, String&amp; startChangeId, String&amp; endChangeId, Int32 Timeout, Boolean&amp; moreChanges)
  at Microsoft.SharePoint.SoapServer.SiteData.GetChanges(ObjectType objectType, String contentDatabaseId, String&amp; LastChangeId, String&amp; CurrentChangeId, Int32 Timeout, Boolean&amp; moreChanges)
  </code></pre>
  <p>However, I'm not able to find any references to that error. I can't even found the method ParseChangeToken from SPChangeToken class (<a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spchangetoken_methods.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spchangetoken_methods.aspx</a>), so this is confusing.</p>
  <p>I already saw this question, however this doesn't solve my issue: <a href="https://stackoverflow.com/questions/1471028/how-to-use-the-getchanges-method-of-sitedata-webservice">Other question</a></p>
  <p>Can anyone help me calling this web service correctly?</p>
  <p><strong>EDIT</strong></p>
  <p>Tried calling it from a C# application to determine that the issue is not with Java. This is the code:</p>
  <pre><code>SiteData.SiteDataSoapClient siteDataService = new SiteData.SiteDataSoapClient();
  siteDataService.Endpoint.Address = new System.ServiceModel.EndpointAddress(&quot;URL/_vti_bin/sitedata.asmx&quot;);
  siteDataService.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(&quot;username&quot;, &quot;password&quot;, &quot;domain&quot;);
  siteDataService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
  
  String startChangeId = &quot;1;1;69d025ce-96a7-4131-adc0-7da1603e8d24;634439002539570000;46914&quot;;
  String endChangeId = &quot;&quot;;
  bool hasMoreChanges = false;
  String databaseID = E5C5E20A-5A9F-406C-B9F6-28923750CECD; //Got it by querying SharePoint database. Any idea how to get it programatically?
  String result = siteDataService.GetChanges(SiteData.ObjectType.SiteCollection, databaseID, ref startChangeId, ref endChangeId, 0, out hasMoreChanges);
  return result;
  </code></pre>
  <p>However, I got 'Microsoft.SharePoint.SoapServer.SoapServerException' and the detail of this exception is null. Used <a href="http://www.fiddler2.com/fiddler2/" rel="nofollow noreferrer">Fiddler</a> to spy on the XML returned by the SharePoint server, and found the same 'Object reference not set to an instance of an object' exception.</p>
  <p>So this certainly means there is something wrong with the parameters I'm passing, right?</p>
  <p>Thanks!!</p>
  <p><strong>Edit</strong></p>
  <p>If someone is interested, I made this work too by setting StartChangeId to LastChangeId and EndChangeId to CurrentChangeId in the XML message.</p>