Creating
a Custom WCF Service in SharePoint Server:-
Add This Code to IRevert.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService
{
[ServiceContract]
public interface IRevert
{
[OperationContract]
void Revert(string listName, int listItemId);
}
}
Add This Code to Revert.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService
{
using Microsoft.SharePoint.Client.Services;
using System.ServiceModel.Activation;
using Microsoft.SharePoint;
[BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class RevertService : IRevert
{
public void Revert(string listName, int listItemId)
{
SPList oList = SPContext.Current.Web.Lists[listName];
SPListItem oItem = oList.GetItemById(listItemId);
if (oItem.Versions.Count > 1)
{
oItem.Versions.Restore(1);
}
}
}
}
<%@ServiceHost Language="C#" Debug="true"
Service="WcfService.RevertService,
$SharePoint.Project.AssemblyFullName$"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory,
Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
Add to this .csproj file:-
<TokenReplacementFileExtensions>svc</TokenReplacementFileExtensions>
Run below Command:
svcutil.exe
http://<server-name>/_vti_bin/CustomWCF/Revert/Revert.svc/mex?wsdl
After run we can see generated two file in this path "C:\wcftest"
1. output.config file
2. RevertService.cs file
Source: http://msdn.microsoft.com/en-us/library/ff521581(v=office.14).aspx
Thank You.
No comments:
Post a Comment