Tuesday, September 06, 2011

Custom Webservices Sharepoint 2010

1)Create a asp.net web service in sp2010 with framework3.5.
a)File New select Web Site select .NET Framework3.5 select VisualC#-->selectASP.NET Webservice Template select FileSystem enter location Click OK.
b)create a Class Library Project in The same Web Service Application.
c)Add the reference to System.Web.Services namespace in the Class Library.
d)delete the class.cs file ,and drag the service.cs into ClassLibrary Project .
e)delete the service.cs file from the App_Code.
f)create the Strong for the ClassLibrary .and add the dll into GAC.
g)go to assembly folder and choose the dll file and RC on the dll file choose properties,copy the PublicKeyToken,Version,Culture.
h)Goto Solution Explorer Dbl_Click on service.asmx and add the following Code
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>
Changed to
<%@ WebService Language="C#" Class="Service, MyServiceAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f2dca3c0f2d0131" %>

i)Rename the asmx file (CustomWebservice.asmx)
2) Generating and Modifying Static Discovery and WSDL Files
1)copy the asmx file into _layouts Folder
2Run the Disco at the command prompt from the LAYOUTS directory to generate .disco and .wsdl files. Run a command in the following format to generate the files in \LAYOUTS:
1. disco http://MyServer/_layouts/MyCustomWebService.asmx
use this command automatically disco file and wsdl files are created.
2. Rename both files in the respective formats MyCustomWebServicedisco.aspx and MyCustomWebServicewsdl.aspx so that your service is discoverable through SharePoint Foundation.
Deploying the Web Service Files to the _vti_bin Directory
The _vti_bin virtual directory maps physically to the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI directory, which contains the default Web service files that are used in SharePoint Foundation. Copy the new MyCustomWebServicewsdl.aspx and MyCustomWebServicedisco.aspx files, and also the MyCustomWebService.asmx file, to the ISAPI folder.
From the _vti_bin directory, a Web service offers its functionality to the site that is specified when adding a Web reference for the service.
To verify that your custom Web service is discoverable, navigate to http://MyServer/_vti_bin/MyCustomWebService.asmx.
Listing the New Web Service in spdisco.aspx
________________________________________
To make your Web service discoverable in Visual Studio as a Web service along with the default SharePoint Foundation Web services, open the spdisco.aspx file that is located in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI and add the following code, specifying the .asmx file for your Web service.
Web_Reference_Folder.MyServiceClass MyCustomService = new Web_Reference_Folder.MyServiceClass();
MyCustomService.UseDefaultCredentials = true;
MessageBox.Show(MyCustomService.HelloWorld());


using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;


SPWeb myWebSite = SPContext.Current.Web;
SPListCollection lists = myWebSite.Lists;

return (myWebSite.Title + " contains " + lists.Count.ToString() +
" lists.");


1. To rebuild the class library DLL and copy it to the GAC, repeat steps 8 and 9 in "To create an ASP.NET Web service."
2. Reset Internet Information Services (IIS) for changes in the DLL to take effect.
3. To generate new versions of the .disco and .wsdl files, repeat the steps in "To generate the static discovery and WSDL files," but change the method binding name in the .disco file as appropriate, for example, to GetSiteListCount.
4. Copy the new versions of the MyCustomWebServicedisco.aspx and MyCustomWebServicewsdl.aspx files to the ISAPI folder.
5. Open the Windows application that you created previously, delete the previous Web service reference for the Hello World example, change the method name as appropriate, and add a new Web reference to the revised Web service.
6. Press F5 to compile and run the project and see a message box that displays the Web site name and the number of lists that it contains.

SharePoint 2010 Central Administration and Configuration Mapping


WCF Services in SharePoint Foundation 2010

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

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

http://msdn.microsoft.com/en-us/library/ff521582.aspx
http://msdn.microsoft.com/en-us/library/ms464040.aspx


Web Services and SharePoint: How do I do it?


[SP2010] Web Services Changes



Getting Started With SharePoint 2010 Web Services


Overview of using REST in SharePoint 2010


WCF: Consuming Claims-Enabled WCF Web Services as SharePoint 2010 External Content Types (Part 4 of 4)


SharePoint sites creation using C# through WebServices


Programmatically Creating SubSite Using Sharepoint Admin.asmx webservice in SharePoint



SharePoint 2010: Create Custom WCF Service


http://www.onlysharepoint2010.com/2011/06/how-to-create-custom-webservice-in.html

http://discoverter.codeplex.com/


Writing Custom Web Service for SharePoint in Supported Mode

1. We will put our custom Web Services in a Custom folder under _vti_bin. In this case we will create new folder WSCustom under (12hive/ISAPI for SharePoint 2007 or 14hive/ISAPI for SharePoint 2010)
2. We will need a helper to read SharePoint context (SPVirtualPath) before passing the request to the real ASMX. In this case we will copy WSDISCO.ASPX and WSWSDL.ASPX from original _VTI_BIN to _VTI_BIN/WSCustom folder
3. We will need custom SPDisco.aspx for our web services, in this case I will name it WSCustomSPDisco.aspx. This is the file, where we will register our web service. (Note the registration is optional, but it is required for truly SharePoint integration)
4. We need an interceptor so that request to SPDisco.aspx will return combination between original SPDisco.aspx and WSCustomSPDisco.aspx. In this case, we will create WSCustomHttpHandler that combine XML from the two files.
5. We need rules to add rules to redirect request to _vti_bin/spdisco.aspx to our WSCustomHttphandler.

In the diagram, the scenario will look like this


































1. Create ASPNET Web Services using Visual Studio.
You can follow instruction in MSDN here (http://msdn.microsoft.com/en-us/library/dd583131(v=office.11).aspx) and stop until “To copy the Web service files to the _vti_bin virtual directory”).

2. Create custom folder for your project under _vti_bin (for example 12hive/ISAPI/CustomWS for SharePoint 2007 or 14hive/ISAPI/CustomWS for SharePoint 2010). In this custom folder, we will put 3 files for every web service (*.asmx) which are:
* .asmx , where is your web service file.
* .aspx , where is corresponding DISCO file of your web service.
* .aspx , where is corresponding WSDL file of your web service.
3. Copy ISAPI\spdisco.aspx to ISAPI\spdisco.disco.aspx . We need copy of original spdisco.aspx, since we don’t want to have infinite loop in our HttpHandler later.
4. Create ISAPI\customws.spdisco.aspx. In this file, we will register our custom web service. This is important to avoid modifying SharePoint built-in file.
5. Create HttpHandler to combine content of spdisco.aspx and *.spdisco.aspx.
6. Register HttpHandler in web.config. We will intercept all _vti_bin/spdisco.aspx with our HttpHandler.


Here Usefull Links

1)Walkthrough: Creating a Custom ASP.NET Web Service
2)spDev
3)SharePoint for Developers Part 6 – Custom web services
4)Web Services and SharePoint: How do I do it?
5)wcf


Overview of WCF and the PSI


Consuming ASMX Web Services with Silverlight


How to Create an ASMX Web Service on SharePoint 2010, Using Visual Studio 2010


Create Simple Web Service in Visual Studio 2008 / 2010




Working with Data Sources and Web Services connections in SharePoint Designer 2010

Link1

No comments:

Blog Archive