SharePoint 2013创建WCF REST Service
SharePoint 2013为开发者提供了丰富的REST API,方便了我们在客户端操作List中的数据。当然我们也可以在SharePoint 2013中创建自定义的REST Service,比如通过REST Service去操作数据库。本篇博客将介绍怎样在SharePoint 2013创建WCF REST Service。
SharePoint 中 创建WCF Service
因为无法在SharePoint 2013 Project中添加WCF Service Template,所以预先创建一个WCF Service Application , 在把契约接口和svc服务拖到SharePoint Project中。所以你需要以下步骤:
- 1.创建 WCF Service Application
- 2.在SharePoint Project中创建SharePoint Mapped Folder ISAPI,因为SharePoint 2013中能访问的服务(.svc)存在:C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\isapi 文件夹中,对应于IIS中虚拟目录_vti_bin。
- 3.把WCF Service Application的svc拖到 ISAPI文件夹中,如下所示:

- 4.修改Namespace,并添加程序集引用,如下所示:

- 5.因为SharePoint Project需要强名称Key File,所以引用此程序集需要提供PublicToken(sn -T assembly.dll,使用方法参考:http://www.cnblogs.com/OceanEyes/p/custom-provider-in-sharepoint-2013-fba-authentication.html)

- 6.修改svc
<%@ ServiceHost Language="C#" Debug="true" Service="Eyes.CustomRestService.Service1,Eyes.CustomRestService,Version=1.0.0.0,Culture=neutral,PublicKeyToken= bf65dbaa17f24124" CodeBehind="Service1.svc.cs" %>
- 7.为了测试WCF Service是否成功部署,需要实现契约接口:
创建用于测试的契约接口:
[ServiceContract]
public interface IService1
{ [OperationContract]
[WebGet(ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="GetData/{value}")]
string GetData(string value); // TODO: Add your service operations here
}
接着实现契约接口,也就是我们的服务:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
- 8.最后,修改Config文件
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="Service1ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Eyes.CustomRestService.Service1" behaviorConfiguration="Service1ServiceBehavior">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="Eyes.CustomRestService.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
- 9.客户端访问REST Service

小结
SharePoint 2013的REST API 十分强大,有时间再分享SharePoint 2013 REST API方面的知识。
SharePoint 2013创建WCF REST Service的更多相关文章
- SharePoint 2013 调用WCF服务简单示例
内容比较简单,主要记录自己使用SharePoint 2013WCF服务遇到的小问题和小经验,分享给大家,希望能够给需要的人有所帮助.好吧,进入正题! 第一部分 SharePoint 2013调用自带W ...
- SharePoint 2013 创建Web Application
今天继续SharePoint 2013 的探索之旅,之前几篇文章分析了SharePoint 2013的物理拓扑结构,安装,以及逻辑体系结构.在这篇文章中,我将继续Step By Step形式演示如何在 ...
- SharePoint 2013 创建搜索中心及搜索设置
本文没有太多深奥的东西,只是简单的搜索配置,如果你已经掌握请略过本文. 好了,进入内容简介,众所周知,搜索是SharePoint一大特性,下面,我们简单介绍下搜索中心的创建. 1.创建Search子网 ...
- SharePoint 2013 创建一个搜索中心和搜索设置
这篇文章不是太多深奥的东西,只是一个简单的搜索配置,假设你已经有了,请跳过这篇文章. 行,输入信息,大家都知道,搜索SharePoint一个主要特征.下列,我们在搜索中心创建个人资料. 1.创建Sea ...
- SharePoint 2013 创建 Site Collection
在之前的文章中,通过SharePoint Central Administration 创建了Web Application.在这篇文章中将继续SharePoint 2013之旅——还是以Step B ...
- sharepoint 2013创建外部内容类型并创建外部列表
步骤: 1.如何:基于 SQL Server 表创建外部内容类型 How to: Create an External Content Type Based on a SQL Server Table ...
- SharePoint 2013创建应用程序时IIS端口文件夹下没文件
最近SharePoint 2007迁移到2013的时候,碰到创建应用程序时IIS端口文件夹下没文件的问题,网上找了大把的原因,终于在这里找到了解决方案: Fix: 1. Open IIS on the ...
- sharepoint 2013 创建母版页
一.创建新的母版页, 并添加了新的样式表 1.从CodePlex 上获得Starter Master Pages for SharePoint 2010 或复制以下母版代码 <%@Master ...
- SharePoint 2013 创建web应用程序报错"This page can’t be displayed"
错误描述 This page can’t be displayed •Make sure the web address http://centeradmin is correct. •Look fo ...
随机推荐
- loadscript加载
function load_script(xyUrl, callback){ var head = document.getElementsByTagName('head')[0]; var scri ...
- 让.aspx同样实现.ashx文件的功能: IHttpHandler
我们需要一个能够调用该处理程序的入口点.在此上下文中,该处理程序代码的入口点只不过是一个HTTP终点——即,一个公共的URL.该URL必须有一个惟一的名称,使IIS和ASP.NET运行库能够把它映射到 ...
- LintCode: Combination Sum II
C++ DFS class Solution { public: void help(vector<int> &a, int now, int sum, int target, v ...
- Android 之 Fagment 完全解析
Android 上的界面展示都是通过 Activity 实现的,Activity 非常常用,不再赘述.但是 Activity 也有它的局限性,同样的界面在手机上显示可能很好看,在平板上就未必了,因为平 ...
- 【Linux】好玩的linux命令
Linux里面有很多有趣的东西,这篇文章整理了一些.摘录一下: 1. sl 命令 你会看到一辆火车从屏幕右边开往左边...... 安装 $ sudo apt-get install sl 运行 $ ...
- uni-app - 支付(app支付、小程序支付、h5(微信端)支付)
App支付.小程序支付.h5(微信端)支付 APP支付(内置) appPay.js /** * 5+App支付,仅支持支付宝以及微信支付 * * 支付宝Sdk集成,微信sdk未集成 * * @para ...
- 磁盘I/O的性能评估方法
磁盘I/O的性能评估方法 http://blog.synology.com/blog/?p=2086 通常,我们很容易观察到数据库服务器的内存和CPU压力.但是对I/O压力没有直观的判断方法.磁盘有两 ...
- auto_ptr,unique_ptr,shared_ptr,weak_ptr
http://mojijs.com/2016/08/218129/index.html http://www.cnblogs.com/lanxuezaipiao/p/4132096.html
- mint 设置无线 AP
所需软件: sudo apt-get install hostapd 1. 创建 hostapd 的 configure 文件 新建 hostapd.conf 文件,存放位置任意,与后面修改的路径一致 ...
- Java关闭Socket来终止线程
Java代码: package Threads; import java.io.BufferedReader; import java.io.IOException; import java.io.I ...