Search This Blog

Saturday, December 6, 2014

Services (Web Service,WCF,Out Of Box) Used In SharePoint 2010

1- Web SerVices

Call SharePoint Web Services from an asp.net web application

Call SharePoint Web Services from the context of current logged-in user from an ASP.NET Web Site/Application that has Windows Authentication enabled

SharePoint Web Services provide methods that you can use to work remotely with a deployment of SharePoint.

Step-1 : Create a Asp.Net 3.5 Web Application and add a service reference in to your application






















Step-2: Write logic to get SharePoint list data. If your list in any other SiteCollection, then use the below url..




----
2- WCF Services

Create and Consume a simple WCF service to add new list item in SharePoint 2010

Step-1 :
Create a new WCF Application project from Visual Studio and named it "Wcf_ListService"

Code for IService.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace Wcf_ListService
{
  // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface     name "IService1" in both code and config file together.
 [ServiceContract]
 public interface IService
    {
     [OperationContract]
     string CreateCustomerList(string siteUrl, clsCustomers objCustomer);
    }


// Use a data contract as illustrated in the sample below to add composite types to service operations.
  [DataContract]
  public class clsCustomers
  {
   string _customerName = "";

    [DataMember]
    public string CustomerName
    {
      get { return _customerName; }
      set { _customerName = value; }
    }
  }
}


Code for Service.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Microsoft.SharePoint;

namespace Wcf_ListService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service : IService
{ 
public string CreateCustomerList(string siteUrl, clsCustomers objCustomer)
{
 string Message = string.Empty;

  try
   {
     SPWeb myWeb = null;

      //The following code must be executed with Elevated rights.
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {

   //Use SPUserTaken'sSystemAccount property so that call for the WCF service hosted on IIS
   //can be made to the SharePoint site.
     using (SPSite mySiteCollection = new SPSite(siteUrlSPUserToken.SystemAccount))
      {
       mySiteCollection.AllowUnsafeUpdates = true;
       myWeb = mySiteCollection.OpenWeb();
      }
   });


 if (myWeb != null)
 {
   myWeb .AllowUnsafeUpdates = true;
   SPList list = myWeb .Lists["lstCustomers"];
   SPListItem Item = list.Items.Add();
   Item["Title"] = objCustomer.CustomerName;
   Item.Update();
   myWeb.AllowUnsafeUpdates = false;
   Message = "Customer Added Successfully";
  }
 else
  {
    Message = "Error";
  }

}
catch (Exception ex)
 {
   Message = ex.Message;
 }
return Message;
        }
    }
}


Step-2:
Our wcf service is ready now build the application.

Step-3:

Consuming WCF Service:

1- Create a ConsoleApplication/WindowApplication/WebApplication 
2- Right click on project and click Add Service Reference
3- A window will appear, click on Discover after that you will see your service listed below.
4- Give it a name as "CustomerRef", click on ok.
5- Now your wcf service reference added to your project.


Here is the code I used in my Consumer site. 

CustomerRef.ServiceClient proxy = new CustomerRef.ServiceClient();
CustomerRef.clsCustomers customers = new CustomerRef.clsCustomers()
    {
      CustomerName="mohit"
    };

string Msg = proxy.CreateCustomerList("http://myServer/sites/mySite/", customers);
Response.Write(Msg);

3- Out Of Box Services 

Out of the Box Web Services in SharePoint

There are a number of web services implemented OOTB (out of the box) in SharePoint that will address most of the common and basic tasks, from administrative tasks to search and working with list data, and much more. Below is a listing of the SharePoint web services with an overview of the functionality exposed for your reference. A simple expanded list like this helps me in working with the web services giving me a quick view of the overall services and methods available.

Service
Administration
(_vti_adm/Admin.asmx)
Administrative methods for creating deleting sites and retrieving languages used in the deployment
  • CreateSite
  • DeleteSite
  • GetLanguage
  • RefreshConfigCache
Alerts (Alerts.asmx)
Methods for working with SharePoint list item alerts
  • DeleteAlerts
  • GetAlerts
Authentication (Authentication.asmx)
Client proxy that provides user authentication for sites that use forms-based authentication
  • Login (Used to authenticate)
  • Mode (Returns the authentication mode of the current site)
Copy (Copy.asmx)
Methods to copy files between or within sites
  • CopyIntoItems (Copy document as byte array to location on server)
  • CopyIntoItemsLocal (Copy document from one location on the same server to another)
  • GetItem (Creates a byte array of a document that can be passed to theCopyIntoItems method)
Document Workspace (Dws.asmx)
Methods for managing Document Workspace sites and data
  • CanCreateDwsUrl
  • CreateDws
  • CreateFolder
  • FindDwsDoc
  • GetDwsData
  • GetDwsMetaData
  • RemoveDwsUser
  • RenameDws
  • UpdateDwsData
Forms (Forms.asmx)
Methods for returning forms that are used in the user interface when working with the contents of a list
  • GetForm
  • GetFormCollection
Imaging (Imaging.asmx)
Methods to create and manager picture libraries
  • CheckSubwebAndList
  • CreateNewFolder
  • Delete
  • Download
  • Edit
  • GetItemsByIds
  • GetItemsXMLData
  • GetListItems
  • ListPictureLibrary
  • Rename
  • Upload
List Data Retrieval (DspSts.asmx)
Perform queries against sites and list in SharePoint
  • Query (Performs queries against SharePoint lists and sites)
Lists (Lists.asmx)
Methods for working with Lists and List Data
  • AddAttachment
  • AddDiscussionBoardItem
  • AddList
  • AddListFromFeature
  • ApplyContentTypeToList
  • DeleteAttachment
  • DeleteContentType
  • DeleteContentTypeXmlDocument
  • DeleteList
  • GetAttachmentCollection
  • GetList
  • GetListAndView
  • GetListCollection
  • GetListContentType
  • GetListContentTypes
  • GetListItemChanges
  • GetListItemChangesSinceToken
  • GetListItems
  • GetVersionCollection
  • UndoCheckout
  • UpdateContentType
  • UpdateContentTypesXmlDocument
  • UpdateContentTypeXmlDocument
  • UpdateList
  • UpdateListItems
Meetings(Meetings.asmx)
Create and manage Meeting Workspace Sites
  • AddMeeting
  • AddMeetingFromICal
  • CreateWorkspace
  • DeleteWorkspace
  • GetMeetingInformation
  • GetMeetingWorkspaces
  • RemoveMeeting
  • RestoreMeeting
  • SetAttendeeResponse
  • SetWorkspaceTitle
  • UpdateMeeting
  • UpdateMeetingFromICal
People(People.asmx)
Resolve and find Principals
  • ResolvePrincipals
Permissions (Permissions.asmx)
Methods for working with permissions for a site or list
  • AddPermission
  • AddPermissionCollection
  • GetPermissionCollection
  • RemovePermission
  • RemovePermissionCollection
  • UpdatePermission
Directory Management(sharepointemailws.asmx)
Methods for managing Active Directory e-mail distribution groups and their memberships
  • ChangeContactsMembershipInDistributionGroup
  • ChangeUsersmembershipInDistributionGroup
  • CreateContact
  • CreateDistributionGroup
  • DeleteContact
  • DeleteDistributionGroup
  • GetJobStatus
  • ModifyContact
  • ModifyDistributionGroup
  • RenameDistributionGroup
Site Data (SiteData.asmx)
Methods that return metadata or list data from sites or lists
  • EnumerateFolder
  • GetAttachments
  • GetChanges
  • GetContent
  • GetList
  • GetListCollection
  • GetListItems
  • GetSite
  • GetSiteAndWeb
  • GetSiteUrl
  • GetURLSegments
  • GetWeb
Sites(Sites.asmx)
Methods for returning information about the collection or site template
  • ExportWeb
  • GetSiteTemplates
  • GetUpdatedFormDigest
  • ImportWeb
Search(spsearch.asmx)
Methods for searching via search services
  • Query
  • QueryEx
  • Registration
  • Status
Users & Groups(usergroup.asmx)
Methods for working with users role definitions and groups
  • AddGroup
  • AddGroupToRole
  • AddRole
  • AddRoleDef
  • AddUserCollectionToGroup
  • AddUserCollectionToRole
  • AddUserToGroup
  • AddUserToRole
  • GetAllUserCollectionFromWeb
  • GetGroupCollection
  • GetList
  • GetListAndView
  • GetListCollection
  • GetGroupCollectionFromRole
  • GetGroupCollectionFromSite
  • GetGroupCollectionFromUser
  • GetGroupCollectionFromWeb
  • GetGroupInfo
  • GetRoleCollection
  • GetRoleCollectionFromGroup
  • GetRoleCollectionFromUser
  • GetRoleCollectionFromWeb
  • GetRoleInfo
  • GetRolesAndPermissionsForCurrentUser
  • GetRolesAndPermissionsForSite
  • GetUserCollection
  • GetUserCollectionFromGroup
  • GetUserCollectionFromRole
  • GetUserCollectionFromSite
  • GetUserCollectionFromWeb
  • GetUserInfo
  • GetUserLoginFromEmail
  • RemoveGroup
  • RemoveGroupFromRole
  • RemoveRole
  • RemoveUserCollectionFromGroup
  • RemoveUserCollectionFromRole
  • RemoveUserCollectionFromSite
  • RemoveUserFromGroup
  • RemoveUserFromRole
  • RemoveUserFromSite
  • RemoveUserFromWeb
  • UpdateGroupInfo
  • UpdateRoleDefInfo
  • UpdateRoleInfo
  • UpdateUserInfo
Versions (Versions.asmx)
Methods for working with file versions
  • DeleteAllVersions
  • DeleteVersion
  • GetVersions
  • RestoreVersion
Views(Views.asmx)
Methods for working with list views
  • AddView
  • DeleteView
  • GetViewCollection
  • GetViewHtml
  • UpdateView
  • UpdateViewHtml
  • UpdateViewHtml2
Web Part Pages(WebPartPages.asmx)
Methods for working with Web Part Pages
  • AddWebPart
  • AddWebPartToZone
  • AssociateWorkflowMarkup
  • ConvertWebPartFormat
  • DeleteWebPart
  • ExecuteProxyUpdates
  • FetchLegalWorkflowActions
  • GetAssemblyMetaData
  • GetBindingResourceData
  • GetCustomControlList
  • GetDataFromDataSourceControl
  • GetFormCapabilityFromDataSourceControl
  • GetSafeAssemblyInfo
  • GetWebPart
  • GetWebPart2
  • GetWebPartCrossPageCompatibility
  • GetWebPartPage
  • GetWebPartPageConnectionInfo
  • GetWebPartPageDocument
  • GetWebPartProperties
  • GetWebPartProperties2
  • RemoveWorkflowAssociation
  • RenderWebPartForEdit
  • SaveWebPart
  • SaveWebPart2
  • ValidateWorkflowMarkupAndCreateSupportObjects
Webs(Webs.asmx)
Methods for working with sites and subsites
·CreateContentType
·CustomizeCss
·DeleteContentType
·GetActivatedFeatures
·GetAllSubWebCollection
·GetColumns
·GetContentType
·GetContentTypes
·GetCustomizedPageStatus
·GetListTemplates
·GetWeb
·GetWebCollection
·RemoveContentTypeXmlDocument
·RevertAllFileContentStreams
·RevertCss
·RevertFileContentStream
·UpdateColumns
·UpdateContentType
·UpdateContentTypeXmlDocument
·WebUrlFromPageUrl
MOSS Search (Search.asmx)
Methods for searching via MOSS (Microsoft Office SharePoint Server) Search services, which also includes a method to retrieve the managed search properties
  • GetSearchMetadata (Search managed properties)
  • Query
  • QueryEx
  • Registration
  • Status

No comments:

Post a Comment