August 13, 2012

Use the sitecore webservice

Recently, I have used the sitecore webservices for the first time to run some jobs without the sitecore context.
If you plan to use it, you will need to choose between the sitecore webservice or the sitecore rocks webservice.

  • The sitecore webservice
    • + Included in sitecore by default
    • + Secured (you need to pass some credentials to execute the methods) 
    • Very basic 
  • The sitecore rocks webservice
    • + Include all feature from the basic one and add some functionalities
    • + Secured (you need to pass some credentials to execute the methods)
    • Need to add the webservice before using in (not by default in sitecore but it is only 2-3 files to copy)
To use the webservice you need to:
  1. Create a reference to your webservice into your project
  2. Create some credentials
    • Sitecore WS:
      OldWS.Credentials oldCredentials = new OldWS.Credentials();
      oldCredentials.UserName = @"sitecore\admin";
      oldCredentials.Password = "b";
    • Rocks WS:
      RocksWS.Credentials credentials = new RocksWS.Credentials();
      credentials.UserName = @"sitecore\admin";
      credentials.Password = "b";
  3. Create an instance of the webservice
    • Sitecore WS
      OldWS.VisualSitecoreServiceSoapClient oldWs = new OldWS.VisualSitecoreServiceSoapClient();
    • Rocks WS
      RocksWS.SitecoreWebService2SoapClient ws = new RocksWS.SitecoreWebService2SoapClient();
  4. Use the methods of the webservice for example
    • GetChildren:
      • Sitecore WS
        //The parent item
        const string dictionaryId = "{504AE189-9F36-4C62-9767-66D73D6C3084}";
        var dictionaryChildren = oldWs.GetChildren(dictionaryId, "master", OldCredentials);
      • Rocks WS
        //The parent item
        const string dictionaryId = "{504AE189-9F36-4C62-9767-66D73D6C3084}";
        var dictionaryChildren = Ws.GetChildren(dictionaryId, "master", Credentials);
Here is the official sitecore documentation: http://sdn.sitecore.net/Reference/Sitecore%206/Sitecore%20Web%20Service%20Reference.aspx

No comments:

Post a Comment