Professional Documents
Culture Documents
WCF Service Integration With SharePoint PDF
WCF Service Integration With SharePoint PDF
Amin, Adnan
http://www.MSTechTalk.com
adnan.amin@hotmail.com
Contents
Delete the default file, and add create a new WCF Service.
I have created a separate layer for Business Logic (class library project) for database related queries,
where I have created an entity framework file and added database table. It will create entity class and
CRUD operations for my entity SubDivision.
Now create a new service application, and call the AddSubdivision method to insert record in database.
public void AddSubDivision(BusinessLogic.Subdivision item)
{
SubdivisionManager _manager = new SubdivisionManager();
_manager.AddSubDivision(item);
In attached code solution, you can also find a service file named FileTranserService
which include the script to upload a file on the server.
Now add the service references to web part solution and select services.
Click on Discover button, it will show current running web services, services can also be selected by
giving full URL. Now select the service and give it a reference name like DNBServiceRefrence and press
OK. It will create a service reference for DNB Service. Similarly, create service reference for
FileTransferService.
After adding service references, you are able to call them . But before calling them, you need to defince
service bindings and Endpoint details in SharePoint sites web.config.
<httpRuntime maxRequestLength="2097152"
The above binding details shows the binding for upload of max file size.
After doing all these configurations, you can now integrate service in custom web part to submit data to
database.
Important: The binding details defined above can be dynamically added in SharePoint sites
web.config using SPWebConfigModification class at the time of feature activation.
Consuming WCF HTTP & HTTPS REST based Service in SharePoint web part
In WCF REST service there are two type of method headers WebGet & WebInvoke, I have developed
REST service using WebInvoke headers.
using System.ServiceModel;
using System.ServiceModel.Web;
Above scripts show the defining of service contract for REST based WCF service.
Now, we have to define the methods in code to update the data. The methods definition is quite simple:
Important here, the endpoint binding details for REST service is defined in the Web.Config of WCF
application.
I have used below bindings for HTTPS based service, and it worked for me.
Above code first post file on the server, then submits data on the servicer which then saved in database
by WCF service.
The service URLs can be set dynamically by multiple ways (through web part properties or web.config).
Just a small modification required in SharePoint sites web.config, set the maxRequestLenth to allow the
maximum upload lenght.