PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Archive for the ‘WebServices’ Category

Failed to load viewstate Error

Posted by PANVEGA on August 27, 2009

When I developed a Custom Webpart I had to build some dynamic added ASP Control (DropDownList etc.) during and after postback. Then I received the follwing error message during the Webpart was changing the Controls.

Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

Reason:

For example, if I dynamically add a textbox to a page, that textbox MUST exist before the viewstate for the page is loaded after a postback. This is because the when the page attempts to load viewstate, the control hierarchy must match the control hierarchy that existed when viewstate was originally created. Read the rest of this entry »

Posted in C#, MOSS, WebServices | Tagged: , , | Leave a Comment »

Lists.asmx/GetListItems Accessing the XmlDocument by using the Namespace

Posted by PANVEGA on March 20, 2009

In this short post I am gonna show you how easy it is accessing the List Item values from the GetListItems method of the Lists.asmx Webservice.

  1. Call your GetListItem method
  2. store the XML in a XmlDocument
  3. You have to build a new XmlNamespaceManage
  4. Add the Namespace properties
  5. In this example I wanna access the XmlNode with the first List Item ID

Read the rest of this entry »

Posted in C#, DotNet, MOSS, WebServices | Tagged: , , , | Leave a Comment »

Query List Items from Lists.asmx Webservice GetListItems

Posted by PANVEGA on March 20, 2009

I created an application where I can retreive a Field ID from a Custon List Item with the Query GetListItem options.

A Query element containing the query that determines which records are returned and in what order, and that can be assigned to a System.Xml.XmlNode object, as in the following example.

  1. Call the GetListItem method
  2. Below you see the parameters from this method
  3. Create a new XmlNode call it “Query”
  4. Create a XmlElement call it “QueryOptions”
  5. Add you custom Query parameters you want
  6. I wanted to query the Item with the ID from the Application Read the rest of this entry »

Posted in C#, DotNet, MOSS, WebServices | Tagged: , , , | 2 Comments »

Deploy a custom Webservice into the SP ISAPI (_vti_bin) filder

Posted by PANVEGA on November 19, 2008

In this article I’ll cover how make a Content Deployment of a custum WebService (.asmx/.disco/.wsdl) to the ISAPI Folder. The dll is going to be deplyed into the WSS bin folder. For some procedures like, for example, adding the web service as a reference in a visual studio project, the discovery (.disco) and wsdl files are required.

read more about deploying inti the bin folder rather GAC in one of my posts Read the rest of this entry »

Posted in Deployment, MOSS, WebServices | Tagged: , | Leave a Comment »

How to implement the SPFeatureReceiver Class to your feature?

Posted by PANVEGA on October 10, 2008

Introductions:

In this post I gonna show you how to implement the SPFEATURERECEIVER class in to your Sharepoint Solution project and give you an example how you can manipulate your Sharepoint Design when activating or deactivating your custom feature. You can use the receiver in almost every custom feature e.g. Webparts, Fieldtypes…

Read the rest of this entry »

Posted in Deployment, MOSS, WebServices | Tagged: , | 2 Comments »

How to create a SQL CLR-Trigger to update MOSS

Posted by PANVEGA on September 9, 2008

In my szenario I should trigger a custom Webservice which consumes a SharePoint Lists.asmx Service in order to add an item to a list. However the client did not want to cosume the custom Webservice in his website. The idea was to throw an trigger in the SQL DB when a website visitor submites a formular and stores it in the DB.

The event or trigger should call the webservice method and collect the appropriate values through a SQL Statement. In the next step the values should commit to the webserice method and call the updatelistitem function and create a new Item in a specific MOSS list.

Read the rest of this entry »

Posted in Deployment, Infrastructure, MOSS, SQL, WebServices | Tagged: , , , | Leave a Comment »

How to access a custom User Subweb List with SP Object Model

Posted by PANVEGA on July 18, 2008

Introduction:

SharePoint provides a solid framework for the .Net developers to write code against and extend sharepoint functionality. As sharepoint is done on ASP.NET 2.0 and have a power code base of .Net Class libraries, a lot of developers can now make use of them and create excellent applications utilizing sharepoint features and libraries.

As I have been working to develop a custom webservice that our organization will use to present all data from multiple sub-sites to a top-level site in a DropDownList when consuming the service with the SP Designer. I want to be able to generate a query on a Sharepoint environment to give me back the list of all the sites that a user is member of. The method returns a XMLDocument for the webservice.

Read the rest of this entry »

Posted in MOSS, Object Model, WebServices, XML | Tagged: , , | Leave a Comment »

How to develope a custom SharePoint WebService

Posted by PANVEGA on April 20, 2008

Szenario

For some procedures like, for example, adding the web service as a reference in a visual studio project or using the SP Designer to consume a Webservice, the discovery (.disco) and wsdl files are required. So we have to develope a WS who need to be registert in SharePoint.  We develope a custom SharePoint Webservice with a .disco and .wsdl file.

Because Windows SharePoint Services virtualizes its URLs (for example, http://MyServer/MySite/MySubsite becomes http://MyServer), you cannot use the autogenerated .disco and .wsdl files generated by ASP.NET. Instead, you must create a .disco page and a .wsdl ASPX page that provide the necessary redirection and maintain virtualization.

I recommend you to make a Content Deplyoment of the service. You do not need a solution.xml file, because you do not have a feature deployment in this special case.

At the end you be able to consume the service like any other SharePoint Webservice.

Information

This web service will work with new versions of SharePoint, Office SharePoint Server 2007 and Windows SharePoint Service 3.0. We gonna use the Webservice I developed in my previous post (access SP all Subites recursive). I have used Microsoft articles as a base for this article.

Create an ASP.NET web service in Microsoft Visual Studio 2005. There are two ways to do this. You can develop a web service on the server machine that hosts SharePoint or you can develop it on a remote machine that does not host SharePoint and later deploy the service on the machine that hosts SharePoint. We will discuss the second method in this article.

Add .ASMX file to your project if it’s not already there. This file will contain the programming logic for the web service. Note, you can add programming logic to the markup page as well as the code behind. The choice is yours. Generate a static discovery file (disco) and a Web Services Description Language (WSDL) file. Modify the disco and wsdl files for SharePoint. Deploy the web service files to the SharePoint server. Create a client application or use SP Designer to consume the web service.

My Class is called AllSitesService which returns a XMLNode. This can be a XMLDocument as well. THe method this.getSubSites(domain) iterates through all Subites.

[WebMethod(Description = “Description: Returns a XML Node with all  first level Subsites from the current SP User. <br/> Enter paramter e.g. http://moss.litwareinc.com&#8221;)]
public XmlNode getAllFirstLevelSubSites(string domain)
{
try
{
if (!domain.Contains(“http://&#8221;))
{
domain = “http://&#8221; + domain;
}
XmlDocument sites = this.getSubSites(domain);
return sites;
}
}
catch (Exception ex)
{
throw (ex);
}
}

Read the rest of this entry »

Posted in C#, Delegate Controls, Deployment, DotNet, MOSS, WebServices | Tagged: , , , , , | Leave a Comment »

Accessing a SP List via Lists.asmx WS by using Views

Posted by PANVEGA on March 19, 2008

In this short post I wanna show you why accessing the Lists.asmx Webservice by giving the appropriate View ID as a parameter. In one of my previous posts I gave you a detail view in this SharePoint Webservice.

https://panvega.wordpress.com/2007/09/15/consuming-listsapsx-webservice-from-sharepoint

I wanna demonstare why it is usefull accesing a custom WS view. If you leave the View parameter in your method  null, the service always reference to the default List View. However usually your default View is what the user should see, when he enters the list. When you wanna hide any fields, which are not interesting for the user, but for your Webservice consumtion, you should build a custom backend View extra for your Webservice.

Note. You only receive the values from the View you just accessed. Other columns are not in your WS return value.

You get the View ID for instance from the URL.

Read the rest of this entry »

Posted in C#, DotNet, MOSS, WebServices | Tagged: , , , | Leave a Comment »

Attachements to a list item using SharePoint Webservices

Posted by PANVEGA on December 16, 2007

In this short post I wanna describe how to add files as an Attachment to a SharePoint list item.

In my previous post Consuming lists.aspx Webservice from SharePoint I showed you how to manage a SharePoint List Webservice. Now I´m gonna add a little bit more tricky thing to the custom cosuming WS method.

Adding an Attachment you need the Add Attchment(..) Method in the lists.asmx Webservice.

public string AddAttachment (
    string listName,
    string listItemID,
    string fileName,
    byte[] attachment
)

Parameters:

listName
A string that contains either the title or the GUID for the list.
listItemID
A string that contains the ID of the item to which attachments are added. This value does not correspond to the index of the item within the collection of list items.
fileName
A string that contains the name of the file to add as an attachment.
attachment
A byte array that contains the file to attach by using base-64 encoding.

Return Value

A string that contains the URL for the attachment, which can subsequently be used to reference the attachment.

Here is an example where I developed a custom ASP.Net Webservice which consumes the Sharepoint lists.aspx Webservice:

[WebMethod(Description = “Set the job appliaction object”)]
public string setApplication(Applicant applicant, string comment, string attache_name, byte[] content)
{

//here follows the CAML XMLElement method, see my previous post for detailed information

……

XmlNode return_node = setservice.UpdateListItems(listname, element);

if (return_node.InnerText == “0×00000000″)

{
if (attache_name != null && content != null)
{
string return_value = setservice.AddAttachment(listname, return_node.SelectSingleNode(“//@ows_ID”).Value, attache_name, content);
setservice.Dispose();
}

}

}

the setApplication(..) function receives an object with all necessary attributes for a job applicant from a ASP.Net Website formular. After adding the job application object successfully to the custom list, go ahead and check the return message. In the return_node you fin the following XML structure:

<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
   <Result ID="1,Update">
      <ErrorCode>0x00000000</ErrorCode>
      <z:row ows_ID="4" ows_Title="Title" ows_Modified="2003-06-19 20:31:21"
         ows_Created="2003-06-18 10:15:58" ows_Author="3;#User1_Display_Name"
         ows_Editor="7;#User2_Display_Name" ows_owshiddenversion="3" ows_Attachments="-1"
         ows__ModerationStatus="0" ows_LinkTitleNoMenu="Title" ows_LinkTitle="Title"
         ows_SelectTitle="4" ows_Order="400.000000000000"
         ows_GUID="{4962F024-BBA5-4A0B-9EC1-641B731ABFED}"
         ows_DateColumn="2003-09-04 00:00:00" ows_NumberColumn="791.00000000000000"
         xmlns:z="#RowsetSchema" />
   </Result>

Check the response ErrorCode message. If you receive this 0x00000000 everything was without any errors.

In the next step choose the setservice.AddAttachment(listname, return_node.SelectSingleNode(“//@ows_ID”).Value, attache_name, content); Method. You need the name or GUID from your SharePointlist.

Now comes the tricky thing, in the return node you see the ows_id attribute with the ID =4. This is the new Item ID you created in the previous step. The ID is important to identify the appopriate item in the list.

Using XPATH to catch the item id from the return node. Then you only need the name and the byte code of the file. Thats all you need to add a file to a Sharepoint item.

ASP.NET Web formular example:

Read the rest of this entry »

Posted in ASP.NET, C#, MOSS, WebServices, XML, XPath | Tagged: , , , , , , , | 2 Comments »

Consuming Lists.asmx Webservice from SharePoint

Posted by PANVEGA on September 15, 2007

In this post I wanna shortly describe how to hanlde with SharePoint Webservice in this case I´m gonna show an examole with the lists.asmx Webservice. SharePoint (WSS 2.0) provides several web services that gives you access to different parts of the object model and its data, without the need to use the object model directly and without worrying where the data is stored in a farm deployment.

The Lists Web service provides methods for working with SharePoint lists, content types, list items, and files. To access this Web service set a Web reference to http://<site>/_vti_bin/Lists.asmx.

Note:

An important detail when programming against the SharePoint web services is to remember to set the .Url property of your web reference to point to the correct WSS team site. The lists.asmx web service is a virtual service and is by SharePoint magic available in all WSS sites, not only in the IIS virtual directory /_vti_bin/. In addition, remember to apply correct credentials for authentication.

Set the .Url like this http://<site>/_vti_bin/Lists.asmx. (avoid getting //_vti_bin/).

So why would we want to use the SharePoint webservice? All site page data and document data is stored in SQL server and compiled into SharePoint pages/documents upon request. It is not recommended that you tamper with the data directly in SQL server as it’s very easy to break a WSS site altogether very easily. That leaves 2 methods of accessing data from a SharePoint database, the SharePoint object model, or webservice.

A full list of webservice methods for things such as alerts and sites are available in the SharePoint Products and Technologies 2003 SDK. I’ll hopefully cover them all in time, but today we’ll focus on just the list webservice.

Here are the methods and their definitions as taken from the SDK:

AddAttachment – Adds an attachment to the specified list item in the specified list.
AddList – Creates a list in the current site based on the specified name, description, and list template ID.
DeleteAttachment – Removes the attachment from the specified list item.
DeleteList – Deletes the specified list.
GetAttachmentCollection – Returns a list of the URLs for attachments to the specified item.
GetList – Returns a schema for the specified list.
GetListAndView – Returns the list and view schemas for the specified list.
GetListCollection – Returns the names and GUIDs for all the lists in the site.
GetListItemChanges – Returns changes made to the list since the specified date and time.
GetListItems – Returns information about items in the list based on the specified query.
UpdateList – Updates a list based on the specified field definitions and list properties.
UpdateListItems – Adds, deletes, or updates the specified items in a list on the current site.

So lets get using this webservice. It’s worth reminding you that I’m using Visual Studio.Net 2003 for this (not VS 2005!). You can add a SharePoint webservice exactly the same way you’d add any other webservice, just right click on the references folder and then ‘Add Web Reference…”. Plant the url to sites webservice you wish to call in the next box, give it a decent name and click ok.

The first webservice method we’ll use is GetList. We can pass in the name of the list as a string as a parameter and it returns an XmlNode with the schema represented in the InnerXml value of the node. The most important piece of information you’ll get is the list guid as you’ll need this do use some of the various other list webservice methods. Here’s our first bit of code:


Site1.Lists listsWS = new SharePointWebservice1.Site1.Lists();
listsWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode list = listsWS.GetList(“Contacts”)
;

Once it’s completed go back to your contacts list on the SharePoint site and you’ll see a field for filling in the ‘Last Contacted’ date for all your contacts.

Note:

When the UseDefaultCredentials property on an instance of a client proxy class is set to true the client will use the default credentials to authenticate to the Web service. The Web service in this sample must be configured to support integrated Windows authentication in the IIS Configuration Permission to properly demonstrate passing default credentials.

The CredentialCache is used to store system credentials for Internet-based resources. By default, when the System.NET.Credential Cache.GetCredentials method is called this compares the URI authentication type provided with any stored in the cache and returns the first set of matching credentials. The DefaultCredentials property is used to represent the system credentials for the current security context in which the application is running. For client-side applications, these are typically the current users’ Windows credentials.

However, within ASP.NET applications these default credentials are either the logged-in user, or the current user being impersonated. It is also important to remember that this property only applies to NTLM, negotiate, and Kerberos based authentication.

Site1.Lists listsWS = new SharePointWebservice1.Site1.Lists();
listsWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode list = listsWS.GetList(“Contacts”);

XmlDocument doc = new XmlDocument();
XmlNode ndProperties = doc.CreateNode(XmlNode.Element, “List”, “”);
XmlAttribute ndTitleAttrib = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, “Title”, “”);
XmlAttribute ndDescription = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, “Description”, “”);
XmlNode ndNewFields = doc.CreateNode(XmlNodeType.Element, “Fields”, “”);

string listName = list.Attributes[”ID”].Value;
string listVersion = list.Attributes[”Version”].Value;

ndTitleAttrib.Value = “Contacts”;
ndDescription.Value = “My contacts list”;

ndProperties.Attributes.Append(ndTitleAttrib);
ndProperties.Attributes.Append(ndDescriptionAttrib);

ndNewFields.InnerXml = “<Method ID=’1′><Field Type=’DateTime’ DateOnly=’TRUE’ Required=’TRUE’
DisplayName=’Last Contacted’ FromBaseType=’TRUE’/></Method>
”;

listsWS.UpdateList(listName, ndProperties, ndNewFields, null, null, listVersion);

The two null values that are passed in are for updateFields and deleteFields. Again for these two fields you need to pass in CAML pretty much the same way as you did for adding fields. Check the SharePoint SDK for values you can pass in to accomplish updates and deletes.

This namespace implements the server-side interface for calling SharePoint-based XML Web services. It contains classes that implement the Windows SharePoint Services Web service and Web services for working with Web Part Pages and Web Parts. In addition, most of the methods within the defined classes are not designed to be called directly from the server but remotely from client applications. The Simple Object Access Protocol (SOAP) interfaces used in these services provide .NET developers with object models that are used to create solutions that work with both WSS and SPS.

Parameters for the CAML Method for updateListItems()

listName A string that contains the internal name of the list.

updates A Batch element that contains one or more methods for updating items and that can be assigned to a System.Xml.XmlNode object, as in the following example.

The ID attribute in each Method element uniquely identifies the specific update so that errors and return values can be properly identified. Each method that is posted contains Field elements that specify the ID of the item and the new field value for the item. The field ID does not correspond to the index of the item in the collection of items for the list.

For descriptions of the various formats used for field types that can be passed in this parameter see SPListItem.

One that could actually be useful, is to be able to actually add new list items to our list using the lists webservice. The method we call for inserting items is the same method used to ammend and delete list items. The Guid of the list is passed in as the first parameter, with the second being an XmlNode. The basics of being able to perform operations on list items is done using CAML again. Below is the code and CAML that I’m going to be running to insert a new item into a custom lists:

returnService = new VIEMossService.Lists();
//returnService.Credentials = System.Net.CredentialCache.DefaultCredentials;
string user = System.Configuration.ConfigurationSettings.AppSettings[“User”];
string password = System.Configuration.ConfigurationSettings.AppSettings[“Password”];
string domain = System.Configuration.ConfigurationSettings.AppSettings[“Domain”];
returnService.Credentials = new NetworkCredential(user, password, domain);
string serviceUrl = System.Configuration.ConfigurationSettings.AppSettings[“ServiceUrl”];

……

all the parameters above and below I added to my custom Webservice web.config file:

<appSettings>
<!–add key=….–>
</appSettings>

You can either chosse the list name or the GUID of the list. YOu find the GIUD in the URL when opening the setting of the list or use the SP Designer to access the proper aspx page.

Note:

In the aspx page you also find the list view ID. So if you wanna access a view with a field which is not included in your custom list then you receive an error. I prefer creating my own Webservice View, with all the neccessary fields.

XmlDocument xmlDoc = new XmlDocument();
/*Use the CreateElement method of the document object to create elements for the parameters that use XML.*/
string listName = System.Configuration.ConfigurationSettings.AppSettings[“ListName“];

try
{
string strBatch = “<Method ID=’1′ Cmd=’New’>” +
“<Field Name=’ID’>New</Field>” +
“<Field Name=’Attachments’>1</Field>” +
“<Field Name=’Email’>” + contact.Email + “</Field>” +
“<Field Name=’Message’>” + contact.Nachricht + “</Field>” +
//”<Field ReadOnly=’TRUE’ Name=’Timestamp’ Type=’DateTime’ DateOnly=’FALSE’ FromBaseType=’TRUE’ ></Field>” +
“</Method>”;

XmlElement element = xmlDoc.CreateElement(“Batch”);
element.SetAttribute(“OnError”, “Continue”);
element.SetAttribute(“PreCalc”, “TRUE”);
element.SetAttribute(“ListVersion”, “1”);
element.SetAttribute(“ViewName”, null);

element.InnerXml = strBatch.ToString();
//Parameter 1: Name of the MOSS List
XmlNode return_node = this.ReturnService.UpdateListItems(listName, element);
if (return_node.InnerText == “0x00000000”)
return true;
return false;

}
catch (SoapException sex)
{
throw (sex);
}

Note:

In this example I added a dummy user with contribute permissions to my custom list. If you give him less permission you receive an error when the Method wants to update or insert an item in the list.

I receive an object from a WebFormular called Contact with all the attributes. In the above CAML you see CMD=new this when you wanna create a new item.

Use a System.Xml.XmlElement object to create a Batch element in Collaborative Application Markup Language (CAML) that can contain multiple Method elements, and use the UpdateListItems method to post the methods and update items. The Cmd attribute of each Method element determines the operation that is performed on an item by specifying one of the following values:

  • Delete — Delete an item.
  • New — Create an item.
  • Update — Modify an item.

Most of the methods from the SharePoint Web services return XmlNode objects. An XmlNode object represents a node in an XML file, plus all of its children, but it isn’t a full XML document. You can use various methods to parse information from an XmlNode.

One of the most important pieces of data being returned is the GUID that uniquely identifies each list within SharePoint Services. This GUID represents the unique identity of the SharePoint list. From putting together this quick sample though I’ve found that title should be just title!  I may well update this article with a better explanation! The message box that is displayed at the end of the code should show 0x00000000 if your item has been successfully added to the list, or report the problem if it can’t.
Return Value of the Webservice

An XMLDATA fragment in the following form that shows the status of each method block posted through the updates parameter and that can be assigned to a System.Xml.XmlNode object. For items successfully updated, a row fragment is returned with the updated row values.

<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
   <Result ID="1,Update">
      <ErrorCode>0x00000000</ErrorCode>
      <z:row ows_ID="4" ows_Title="Title" ows_Modified="2003-06-19 20:31:21"
         ows_Created="2003-06-18 10:15:58" ows_Author="3;#User1_Display_Name"
         ows_Editor="7;#User2_Display_Name" ows_owshiddenversion="3" ows_Attachments="-1"
         ows__ModerationStatus="0" ows_LinkTitleNoMenu="Title" ows_LinkTitle="Title"
         ows_SelectTitle="4" ows_Order="400.000000000000"
         ows_GUID="{4962F024-BBA5-4A0B-9EC1-641B731ABFED}"
         ows_DateColumn="2003-09-04 00:00:00" ows_NumberColumn="791.00000000000000"
         xmlns:z="#RowsetSchema" />
   </Result>

Other example GetListItems WS Method:

Here you have to parse the received DOM XML structure from the GetListItems(). Very importan is the Namespace, whne retreiving the nodes using XPATH.

try
{
xmlDoc.Load(new XmlNodeReader(this.getService().GetListItems(listName, viewName, null, null, null, null, null)));
XmlNode child_node = xmlDoc.FirstChild.FirstChild;

List<Video> list_Videos = new List<Video>();

foreach (XmlNode row_node in child_node)
{
Video video = new Video();
video.Childname = row_node.SelectSingleNode(“@ows_Childname”) != null ? row_node.SelectSingleNode(“@ows_Childname”).Value.Trim() : “”;
video.Description = row_node.SelectSingleNode(“@ows_Description”).Value.Trim();
video.Topic = row_node.SelectSingleNode(“@ows_Topic”).Value.Trim();

….
XmlNamespaceManager nsmgr = new XmlNamespaceManager(
xmlDoc.NameTable);
nsmgr.AddNamespace(“z”, “#RowsetSchema”);
nsmgr.AddNamespace(“rs”, “urn:schemas-microsoft-com:rowset”);
nsmgr.AddNamespace(“rootNS”, “http://schemas.microsoft.com/sharepoint/soap/&#8221;);
….
list_Videos.Add(video);
}
return list_Videos;
}
catch (Exception ex)
{
throw (ex);
}

The SharePoint Web Services

Windows SharePoint Services was being designed and developed during the time when Microsoft was beginning to heavily push Web services. It should be no surprise, then, to find out that you can get at the data in SharePoint through Web services. In fact, there’s not just one Web service involved; there are 16. Here’s a brief rundown of the Web services that a SharePoint server makes available out of the box:

* http://server:5966/_vti_adm/Admin.asmx – Administrative methods such as creating and deleting sites
* http://server/_vti_bin/Alerts.asmx – Methods for working with alerts
* http://server/_vti_bin/DspSts.asmx – Methods for retrieving schemas and data
* http://server/_vti_bin/DWS.asmx – Methods for working with Document Workspaces
* http://server/_vti_bin/Forms.asmx – Methods for working with user interface forms
* http://server/_vti_bin/Imaging.asmx – Methods for working with picture libraries
* http://server/_vti_bin/Lists.asmx – Methods for working with lists
* http://server/_vti_bin/Meetings.asmx – Methods for working with Meeting Workspaces
* http://server/_vti_bin/Permissions.asmx – Methods for working with SharePoint Services security
* http://server/_vti_bin/SiteData.asmx – Methods used by Windows SharePoint Portal Server
* http://server/_vti_bin/Sites.asmx – Contains a single method to retrieve site templates
* http://server/_vti_bin/UserGroup.asmx – Methods for working with users and groups
* http://server/_vti_bin/versions.asmx – Methods for working with file versions
* http://server/_vti_bin/Views.asmx – Methods for working with views of lists
* http://server/_vti_bin/WebPartPages.asmx – Methods for working with Web Parts
* http://server/_vti_bin/Webs.asmx – Methods for working with sites and subsites

To use any of these Web services, replace server with the name of your SharePoint server. Because they’re implemented using ASP.NET code, you can retrieve the matching WSDL file for any service by appending ?WSDL to the end of the URL. When you do so, you’ll discover that each one supports multiple methods, making this one of the richest sets of Web services of any current product. For full information on the available Web methods, download the SharePoint Products and Technologies 2003 SDK.

More Informations:

Shows all SharePoint Webservices

http://msdn.microsoft.com/en-us/library/lists.lists.updatelist.aspx

http://blogs.msdn.com/harsh/archive/2006/08/03/687759.aspx

Posted in ASP.NET, CAML, DotNet, MOSS, SOAP, WebServices, XPath | Tagged: , , , , , , | 1 Comment »

How to Create a RESTful Interface?

Posted by PANVEGA on August 11, 2007

REST (representational state transfer) is an approach for getting information content from a Web site by reading a designated Web page that contains an XML (Extensible Markup Language) file that describes and includes the desired content. ” The terms “representational state transfer” and “REST” were introduced in the doctoral dissertation of Roy Fielding one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification.

For example, REST could be used by an online publisher to make syndicated content available. Periodically, the publisher would prepare and activate a Web page that included content and XML statements that described the content. Subscribers would need only to know the URL (Uniform Resource Locator) for the page where the XML file was located, read it with a Web browser, interpret the content data using the XML information, and reformat and use it appropriately (perhaps in some form of online publication).

REST is an “architectural style” that basically exploits the existing technology and protocols of the Web, including HTTP (Hypertext Transfer Protocol) and XML. REST is simpler to use than the well-known SOAP (Simple Object Access Protocol) approach, which requires writing or using a provided server program (to serve data) and a client program (to request data).

SOAP, however, offers potentially more capability. For example, a syndicator that wanted to include up-to-date stock prices to subscribing Web sites might need to use SOAP, which allows a greater amount of program interaction between client and server.

Motivation for REST

The motivation for REST was to capture the characteristics of the Web which made the Web successful. Subsequently these characteristics are being used to guide the evolution of the Web.

REST – An Architectural Style, Not a Standard

REST is not a standard. You will not see the W3C putting out a REST specification. You will not see IBM or Microsoft or Sun selling a REST developer’s toolkit. Why? Because REST is just an architectural style. You can’t bottle up that style. You can only understand it, and design your Web services in that style. (Analogous to the client-server architectural style. There is no client-server standard.) While REST is not a standard, it does use standards:

  • HTTP
  • URL
  • XML/HTML/GIF/JPEG/etc (Resource Representations)
  • text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)

REST Web Services Characteristics

Here are the characteristics of REST:

  • Client-Server: a pull-based interaction style: consuming components pull representations.
  • Stateless: each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
  • Cache: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.
  • Uniform interface: all resources are accessed with a generic interface (e.g., HTTP GET, POST, PUT, DELETE).
  • Named resources – the system is comprised of resources which are named using a URL.
  • Interconnected resource representations – the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another.
  • Layered components – intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.

Principles of REST Web Service Design

1. The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services.

2. Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:

http://www.parts-depot.com/parts/getPart?id=00345

Note the verb, getPart. Instead, use a noun:

http://www.parts-depot.com/parts/00345

3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.

4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.

5. No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information.

6. Design to reveal data gradually. Don’t reveal everything in a single response document. Provide hyperlinks to obtain more details.

7. Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron). For those services that require a POST or PUT to it, also provide a schema to specify the format of the response. 8. Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.

For example, Amazon’s web services have both SOAP and REST interfaces, and 85% of the usage is on the REST interface. Compared with other styles of web services, REST is easy to implement and has many highly desirable architectural properties: scalability, performance, security, reliability, and extensibility. Those characteristics fit nicely with the modern business environment, which commands technical solutions just as adoptive and agile as the business itself.

A few short years ago, REST had a much lower profile than XML-RPC, which was much in fashion. Now XML-RPC seems to have less mindshare. People have made significant efforts to RESTize SOAP and WSDL. The question is no longer whether to REST, but instead it’s become how to be the best REST?

The purpose of this article is to summarize some best practices and guidelines for implementing RESTful web services. The REST web services architecture is related to the Service Oriented Architecture. This limits the interface to HTTP with the four well-defined verbs: GET, POST, PUT, and DELETE. REST web services also tend to use XML as the main messaging format.

How to Create a RESTful Interface?

Now we get to the meat of the matter. Instead of covering this from an architectural view, I’ll approach it from a recipe perspective, a series of steps you take and questions you can answer, that will hopefully guide you to creating a great REST interface.

To create a REST service, you need to answer the following questions, and you should answer them in this order:

  1. What are the URIs?
  2. What’s the format?
  3. What methods are supported at each URI?
  4. What status codes could be returned?

In laying out these questions, I didn’t use the proper naming conventions; instead, I used the common names for things that most developers are familiar with. As we answer each question, I’ll also introduce the proper nomenclature.

Question 1: What Are the URIs?

The proper nomenclature would be “What are the resources?” The things identified by URIs are “resources.” That is the terminology used in Roy Fielding’s thesis and also the same terminology used in Architecture of the World Wide Web, First Edition. Resources are identified by URIs.

You might be creating a RPC protocol, or worse, if you only have a single URI that everything goes through. Many years ago, one of the first intranet services I put together was a web interface to an ECO (Engineering Change Order) system. Every time a part was changed, an ECO was filed and had to flow through this system. I created a single script that handled the whole system, a single script that took all it’s parameters via POST. That meant there was no way to bookmark a page in the system; each page had the same URI: /cgi-bin/eco.cgi. Employees wanted to bookmark certain ECOs or send shortcuts via email, but they couldn’t because the URI in the address bar never changed. It was always the same, /cgi-bin/eco.cgi, unchanging, like the blinking 12:00 on an unprogrammed VCR. The employees didn’t know about REST, but what they did know implicitly is that each resource, in this case, an ECO, should have its own URI.

Break your problem down into the types of resources you want to manipulate. The thing to remember is that each resource should have its own URI. Try to list all the resources you could possibly need at this step. Two places to consider when looking for potential resources are collections and search interfaces. A “collection of resources” may, in itself, be a whole new resource.

A search interface is another source of resources. You enter criteria for the resources you want to find, and a list of matching resources are returned. You may notice, though, that the results of a search are just a collection of resources, ones that match a particular criteria, and as such, this is really just a narrower version of the first case of a resource collection.

Consider a very simple example of a system for maintaining an employee contact list. For our example, it will contain each employees name, title, and contact information. In such a system, each user should have their own URI with an appropriate representation. That representation should contain the name, title, and contact information for that employee.

There is also a collection of resources that is, in itself, another resource. The collection of all employees is another resource in our system. So we have identified two kinds of resources in this tiny system, and so there will be two types of URIs:

  1. Employee (One URI per employee)
  2. All Employees

After you’ve identified the resources via their URIs, it’s time to consider the next question.

Question 2: What’s the Format?

The proper terminology here is “representation.” You can’t actually reach out and touch the resources behind the URIs you identified in Step 1. What you can do is exchange representations of those resources. When I do a GET on an “employee” resource, I need to get something back which conveys information about that employee. These days HTML, XML, images, sound, and movies are all potential formats that could be used. For now, we’ll restrict ourselves to using XML: it’s a pretty popular format, lots of tools are available to process it, and there is an expectation that when you say “web services,” you are referring primarily to the exchange of XML documents. And, yeah, this is being published on XML.com!

For each of the resources you listed in Step 1, you need to decide what the representations are going to look like. If possible, reuse existing formats if they are applicable. This can increase the chances that your system can be composed with other systems.

In our example employee contact list above, we could have the following representations:

Employee Format
For the sake of exposition, I will make up a new XML format for this information. Exposition–“A statement or rhetorical discourse intended to give information about or an explanation of difficult material”–which just means that I get to cheat as long as you learn something in the process.
<employee xmlns='http://example.org/my-example-ns/'>
    <name>Full name goes here.</name>
    <title>Persons title goes here.</title>
    <phone-number>Phone number goes here.</phone-number>
</employee>
Employee List Format
Since each employee will have his or her own URI with all the details there, our list will only include that URI.
<employee-list xmlns='http://example.org/my-example-ns/'>
    <employee-ref href="URI of the first employee"/>
	 Full name of the first employee goes here.</employee>
    <employee-ref href="URI of employee #2"/>Full name</employee>
    .
    .
    <employee-ref href="URI of employee #N"/>Full name</employee>
</employee-list>

Note that we haven’t mapped the representations to resources just yet. To do that, we need to consider the methods.

Question 3: What Methods Are Supported at Each URI?

In the proper nomenclature, how do the URIs we defined in Step 1 get dereferenced?

Agents may use a URI to access the referenced resource; this is called dereferencing the URI. Access may take many forms, including retrieving a representation of the resource (for instance, by using HTTP GET or HEAD), adding or modifying a representation of the resource (for instance, by using HTTP POST or PUT, which in some cases may change the actual state of the resource if the submitted representations are interpreted as instructions to that end), and deleting some or all representations of the resource (for instance, by using HTTP DELETE, which in some cases may result in the deletion of the resource itself).

We’ll restrict the discussion to accessing resources using one the four basic HTTP methods that can be applied to a URI: GET, POST, PUT, and DELETE. HEAD is really a GET without a response body, and there are also others defined by RFC 2616 like OPTIONS. In addition, specs like WebDAV introduce even more methods. That’s nice, but you should be able to go very far with just the four basic methods, which align nicely with CRUD, an acronym from the database world which stands for Create, Retrieve, Update, and Delete.

HTTP Method CRUD Action Description
POST CREATE Create a new resource
GET RETRIEVE Retrieve a representation of a resource
PUT UPDATE Update a resource
DELETE DELETE Delete a resource

I hesitated to include this table. By presenting it, I wanted to point out the overlap in the four basic methods of HTTP. What I don’t want to happen is that you start thinking of web resources as SQL tables. Don’t do that.

Make sure your GETs are side-effect free. This is a biggie, the one where many services get it wrong. GETs must be both safe and idempotent. In turn, anything which does not have side effects should use GET.

So if you want to create a new resource, use POST. Want to retrieve a representation of a resource? Use GET. To update a current resource, use PUT. Finally, to delete a resource, use DELETE.

Once you have decided on the URIs (Step 1), picked representations (Step 2), and decided on methods (Step 3), you need to match them all up. At the very least, you’ll need to pick a representation for the response of every GET and a representation to place in the request for PUT and POST. Optionally, you may want to consider the representation, if any is returned from a POST.

Let’s go back to our employee contact list, and now we can match up the resources, the representations, and the methods.

Resource Method Representation
Employee GET Employee Format
Employee PUT Employee Format
Employee DELETE N/A
All Employees GET Employee List Format
All Employees POST Employee Format

Question 4: What Status Codes Could Be Returned?

Not only do you need to know what type of representation is returned, you also need to enumerate the typical HTTP status codes that could be returned. In a perfect world, this step wouldn’t be necessary since a good implementation would handle every status code correctly. In practice, you should list all the status codes you expect to return. This will provide good guidance for implementers on the conditions they should be testing for.

We’ll update our table for our employee contact list to include the expected status codes

Resource Method Representation Status Codes
Employee GET Employee Format 200, 301, 410
Employee PUT Employee Format 200, 301, 400, 410
Employee DELETE N/A 200, 204
All Employees GET Employee List Format 200, 301
All Employees POST Employee Format 201, 400

One often hears the criticism that HTTP is synchronous, while many services need to be asynchronous. It is actually quite easy to implement an asynchronous REST service. An asynchronous service needs to perform the following:

  1. Return a receipt immediately upon receiving a request.
  2. Validate the request.
  3. If the request if valid, the service must act on the request as soon as possible. It must report an error if the service cannot process the request after a period of time defined in the service contract.

More References:

http://de.wikipedia.org/wiki/Representational_State_Transfer

http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

http://www.thomas-bayer.com/restnames/

http://dret.net/lectures/services-fall06/rest

Posted in REST, SOAP, WebServices | Tagged: , , , , | Leave a Comment »