Sunday 29 June 2014

How to use MOSS 2007 web services?


Ans.) No Need to write any object model code............................
Just use existing webservices in sharepoint.
Create a new web services application.
Add web references for the Sharepoint site which you want to write you custom services.
Ex:http://[SERVER:Port]/_vti_bin/usergroup.asmx
http://[SERVER:Port]/_vti_bin/lists.asmx
MOSS 2007 web services
Name URL
Administration
http:///_vti_adm/Admin.asmx
Alerts
http:///_vti_bin/Alerts.asmx
Authentication
http:///_vti_bin/Authentication.asmx
Copy
http:///_vti_bin/Copy.asmx
Document Workspace
http:///_vti_bin/Dws.asmx
Forms
http:///_vti_bin/Forms.asmx
Imaging
http:///_vti_bin/Imaging.asmx
List Data Retrieval
http:///_vti_bin/DspSts.asmx
Lists
http:///_vti_bin/Lists.asmx
Meetings
http:///_vti_bin/Meetings.asmx
People
http:///_vti_bin/People.asmx
Permissions
http:///_vti_bin/Permissions.asmx
SharePoint Directory Management
(in stssoap.dll)
Site Data
http:///_vti_bin/SiteData.asmx
Sites
http:///_vti_bin/Sites.asmx
Search
http:///_vti_bin/spsearch.asmx
Users and Groups
http:///_vti_bin/usergroup.asmx
Versions
http:///_vti_bin/Versions.asmx
Views
http:///_vti_bin/Views.asmx
Web Part Pages
http:///_vti_bin/WebPartPages.asmx
Webs
http:///_vti_bin/Webs.asmx
If you want do list related custom code, use "Lists.asmx"...........
Here i am going to write a custom code to upload a attachment in the list.
[WebMethod]
public void Upload(string ListName,byte[] bytestream,string ListItemID, string FileName)
{
try
{
Lists.Lists ListsWebService = new Lists.Lists();
ListsWebService.Credentials = new NetworkCredential("USERID", "PASSWORD", "DOMAIN");
ListsWebService.AddAttachment(ListName, ListItemID, FileName, bytestream);
}
catch (Exception ex)
{
throw ex;
}
}
EX:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.DirectoryServices;
using System.Xml;
using System.Net;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string GetRoles(string FQN) {
string EmailID = string.Empty;
DirectorySearcher UserSearch = new DirectorySearcher("(mailNickName= " + FQN + ")");
SearchResult mYResult = UserSearch.FindOne();
if (mYResult == null)
{
return EmailID;
}
DirectoryEntry EmployeeName = mYResult.GetDirectoryEntry();
EmailID =Convert.ToString(EmployeeName.Properties["Title"].Value);
return EmailID;
}
[WebMethod]
public string DoesUserExists(string UserName, string GroupName)
{
string Exists = "true";
UserGroup.UserGroup webService = new UserGroup.UserGroup();
NetworkCredential mycredentials = new NetworkCredential("blackPoint", "B@Point", "scsdomhyd01");
webService.Credentials = mycredentials;
XmlNode UserGroups = webService.GetGroupCollectionFromUser(UserName);
try
{
foreach (XmlNode node in UserGroups.FirstChild.ChildNodes)
{
string SPGroupName = node.Attributes["Name"].Value.ToLower();
if (GroupName.ToLower() == SPGroupName)
{
return Exists;
break;
}
}
Exists = "False";
return Exists;
}
catch (Exception ex)
{
return ex.Message;
}
}
[WebMethod]
public void DoesUserExistsNew(string UserName, string GroupName, out string Exists)
{
Exists = "true";
UserGroup.UserGroup webService = new UserGroup.UserGroup();
NetworkCredential mycredentials = new NetworkCredential("blackPoint", "B@Point", "scsdomhyd01");
webService.Credentials = mycredentials;
XmlNode UserGroups = webService.GetGroupCollectionFromUser(UserName);
try
{
foreach (XmlNode node in UserGroups.FirstChild.ChildNodes)
{
string SPGroupName = node.Attributes["Name"].Value.ToLower();
if (GroupName.ToLower() == SPGroupName)
{
//return Exists;
break;
}
}
Exists = "False";
//return Exists;
}
catch (Exception ex)
{
//return ex.Message;
Exists=ex.Message;
}
}
[WebMethod]
public void addAttachmentToList(string ListName,byte[] bytestream,string ListItemID, string FileName)
{
try
{
Lists.Lists ListsWebService = new Lists.Lists();
ListsWebService.Credentials = new NetworkCredential("USERID", "PASSWORD", "DOMAIN");
ListsWebService.AddAttachment(ListName, ListItemID, FileName, bytestream);
}
catch (Exception ex)
{
throw ex;
}
}
}