Results 1 to 4 of 4

Thread: How to create a custom web service in Microsoft Sharepoint

  1. #1
    Join Date
    May 2009
    Posts
    218

    How to create a custom web service in Microsoft Sharepoint

    This tight integration between Office 2003 and Sharepoint is known. But have you wondered what happens in practice? Here is revealed the mystery: ... the exchange of data between the two software packages is through the web service, exposed by Sharepoint. These services, 16 for Windows Sharepoint Services and Sharepoint Portal 5 added to allow you to access information outside of their environments, which otherwise would be inaccessible, in addition, in some cases, these can be queried by users with anonymous access (at least in the group clearly Reader Sharepoint site). However, the features offered by these services do not cover all the essential functions of the object model of SharePoint, to overcome this problem, you can create your own web service, however, useful to fill most of the deficiencies.

    Now, let us pause for a moment and clarify a second one thing: this is not to be an article that explains step by step how each web service (the list can be found on ' sdk ), the aim is rather to take a web service as an example, see what are the capabilities and those omitted, and then try to implement a service tailored to our needs. The web service is considered the "Website Service", or the service that is responsible for managing Sharepoint sites. These methods exposed:

    :: GetAllSubWebsCollection
    :: GetListTemplates
    :: GetWeb
    :: GetWebCollection
    :: WebUrlFromPageUrl

  2. #2
    Join Date
    May 2009
    Posts
    218

    Re: How to create a custom web service in Microsoft Sharepoint

    One possible use might therefore be to print within a Web Part, the list of sub-sites of a parent site. But be careful. Surely you're wondering what we are talking about the parent site. Well, you know that the web service exposed by SharePoint are called according to the site from which to get the information. So if I call the web service:

    Code:
    http:// [server_name] / _vti_bin / webs.asmx
    I decide to get information about the site created at: http:// [server_name]. But if I call the web service:

    Code:
    http:// [server_name] / sites / MyWeb / _vti_bin / webs.asmx
    I decide to get information about the site "MyWeb", created under the sitecollection "sites". That said, we take as the sub of the parent site chosen by calling GetWebCollection.

    Code:
      Webs.Webs Webs.Webs webs = new ();
    
      webs.Credentials = CredentialCache.DefaultCredentials;
    
      webs.Url = "http:// <server_name> / sites / MyWeb";
    
      XmlNode webs.GetWebCollection subwebs = ();
    
      foreach (XmlNode node in subwebs.ChildNodes)
    
      {
    
      string title = node.Attributes ["Title"]. Value;
    
      string url = node.Attributes ["Url"]. Value;
    
      }

  3. #3
    Join Date
    May 2009
    Posts
    218

    Re: How to create a custom web service in Microsoft Sharepoint

    As we can see, the method returns an object of type GetWebCollection XmlNode containing a fragment of XML, from which we can take the name and address of any sub. Immediately evident that I am not having more to do with the SharePoint API, but with information in the format string, and very small compared with, for example, to what is offered by an object of type SPWeb . Precisely because of this, we lose a lot of useful features, most notably the ability to make us return only sites in which the current user has permissions, or the ability to see the kind of template for each sub-site or, perhaps, the its ID. To overcome these shortcomings, we must necessarily implement a custom web service, which exploits the most appropriate way the object model of SharePoint.

    This method GetSubWebsForCurrentUser I thought to develop. The return type is always the same (an object of type XmlNode), and can be read with the same code seen before, the only difference, of course, is that Sharepoint sites are returned only when the user makes the request to the web service has rights.

    Code:
    [WebMethod]
    
      public XmlNode GetSubWebsForCurrentUser (string siteurl)
    
      {
    
      XmlDocument doc = new XmlDocument ();
    
      doc.AppendChild (doc.CreateElement ("Website"));
    
      try
    
      {
    
      SPWeb web = new SPSite (siteurl). OpenWeb ();
    
      foreach (SPWeb childWeb in web.GetSubwebsForCurrentUser ())
    
      {
    
      Doc.CreateElement XmlNode childNode = ("Web");
    
      Doc.CreateAttribute XmlAttribute name = ("Name");
    
      name.Value = childWeb.Title;
    
      Url = doc.CreateAttribute XmlAttribute ("URL");
    
      url.Value = childWeb.Url;
    
      childNode.Attributes.Append (name);
    
      childNode.Attributes.Append (url);
    
      doc.DocumentElement.AppendChild (childNode);
    
      }
    
      }
    
      catch (Exception exe)
    
      {
    
      throw new Exception (exe.Message, exe);
    
      }
    
      doc.DocumentElement return;
    
      }
    Here we have two ways to further expand the capabilities of our custom web service. The first returns the name of the template used to create the site as a parameter and the second will return the ID:

    Code:
    [WebMethod]
    
      public string GetTemplateName (string siteurl)
    
      {
    
      SPWeb web = new SPSite (siteurl). OpenWeb ();
    
      web.WebTemplate return;
    
      }
    
      [WebMethod]
    
      public int GetTemplateID (string siteurl)
    
      {
    
      SPWeb web = new SPSite (siteurl). OpenWeb ();
    
      web.WebTemplateId return;
    
      }

  4. #4
    Join Date
    May 2009
    Posts
    218

    Re: How to create a custom web service in Microsoft Sharepoint

    Where to install the web service?

    Ok, once implemented the web service, we assign that location. This, in my opinion, is the most important of all. This is because a web application that tries to get information from SharePoint, to ensure that it functions, should be on a web site that has an IIS Application Pool that runs with a user that has permissions on the database of places on Sql Server Sharepoint .
    The most immediate is then to place the files of the web service inside a new virtual directory located under the IIS site that handles Sharepoint, because that site already has an Application Pool that runs with the right credentials for access to database. Without this, we must add the new virtual directory under "Unmanaged Path" Sharepoint (reached by following this path: Sharepoint Central Administration> Windows Sharepoint Services> Change Virtual Server General Settings> Unmanaged Path), in order to be able to view the pages and prevent them from being directly managed by Sharepoint itself (ie: if we decided to call the virtual directory "Webservices", just enter the name of the paths excluded).

    Carried out these operations, there is nothing left but to consume our web service.

Similar Threads

  1. Replies: 8
    Last Post: 06-05-2012, 12:21 PM
  2. Replies: 5
    Last Post: 24-10-2010, 04:51 AM
  3. How to map a drive to Microsoft Sharepoint folder
    By !const in forum Networking & Security
    Replies: 4
    Last Post: 09-07-2009, 08:34 PM
  4. SharePoint Service Unavailable (Application Pool crashes)
    By PARRISH in forum Small Business Server
    Replies: 3
    Last Post: 19-04-2009, 01:50 AM
  5. Create Custom Keyboard Shortcuts in Microsoft Word
    By Ehsaan in forum Windows Software
    Replies: 3
    Last Post: 06-04-2009, 11:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,025,800.87166 seconds with 17 queries