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 ...
随机推荐
- iOS 获取已安装 的APP
-(void)getAppPlist { Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace ...
- Android 之 应用未捕获异常处理
最近开发一款低功耗蓝牙通讯的 Android 应用,安装使用时多次出现“ 抱歉,xxx已停止 ”.现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不定就出 ...
- Android ART runtime简述
此文章原始是PPT格式已转换为PDF,完整内容也能够下载文档阅读: AndroidARTruntimeOverview watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5 ...
- Mongostat 2.6详解
Mongostat C:\Users\John>Mongostat connected to: 127.0.0.1 insert query update delete getmore comm ...
- itextpdf 备忘
加删除线: .setUnderline(Color.BLACK, 2.0f, 0.0f, 6.0f, 0.0f, 1) https://developers.itextpdf.com/examples ...
- Java多线程的悲观锁与乐观锁
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6561376.html 一:悲观锁 悲观锁,就是不管是否发生多线程冲突,只要存在这种可能,就每次访问都加锁,加 ...
- 在vim中安装及配置NERDTree插件
使用Vundle插件安装,在.vimrc中加入以下代码: Plugin 'scrooloose/nerdtree' 打开vim,输入命令如下: :BundleInstall 等待安装完毕 配置NERD ...
- linux下查看和修改文件时间
一.查看文件时间及相关命令 1.stat查看文件时间 [root@web10 ~]# stat install.log File: "install.log" Size: 3338 ...
- “Info.plist” couldn’t be removed
Showing All Messages error: failed to remove /Users/Rubert/Library/Developer/Xcode/DerivedData/Proje ...
- Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...