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,并添加程序集引用,如下所示:

  • 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的更多相关文章

  1. SharePoint 2013 调用WCF服务简单示例

    内容比较简单,主要记录自己使用SharePoint 2013WCF服务遇到的小问题和小经验,分享给大家,希望能够给需要的人有所帮助.好吧,进入正题! 第一部分 SharePoint 2013调用自带W ...

  2. SharePoint 2013 创建Web Application

    今天继续SharePoint 2013 的探索之旅,之前几篇文章分析了SharePoint 2013的物理拓扑结构,安装,以及逻辑体系结构.在这篇文章中,我将继续Step By Step形式演示如何在 ...

  3. SharePoint 2013 创建搜索中心及搜索设置

    本文没有太多深奥的东西,只是简单的搜索配置,如果你已经掌握请略过本文. 好了,进入内容简介,众所周知,搜索是SharePoint一大特性,下面,我们简单介绍下搜索中心的创建. 1.创建Search子网 ...

  4. SharePoint 2013 创建一个搜索中心和搜索设置

    这篇文章不是太多深奥的东西,只是一个简单的搜索配置,假设你已经有了,请跳过这篇文章. 行,输入信息,大家都知道,搜索SharePoint一个主要特征.下列,我们在搜索中心创建个人资料. 1.创建Sea ...

  5. SharePoint 2013 创建 Site Collection

    在之前的文章中,通过SharePoint Central Administration 创建了Web Application.在这篇文章中将继续SharePoint 2013之旅——还是以Step B ...

  6. sharepoint 2013创建外部内容类型并创建外部列表

    步骤: 1.如何:基于 SQL Server 表创建外部内容类型 How to: Create an External Content Type Based on a SQL Server Table ...

  7. SharePoint 2013创建应用程序时IIS端口文件夹下没文件

    最近SharePoint 2007迁移到2013的时候,碰到创建应用程序时IIS端口文件夹下没文件的问题,网上找了大把的原因,终于在这里找到了解决方案: Fix: 1. Open IIS on the ...

  8. sharepoint 2013 创建母版页

    一.创建新的母版页, 并添加了新的样式表 1.从CodePlex 上获得Starter Master Pages for SharePoint 2010 或复制以下母版代码 <%@Master  ...

  9. 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 ...

随机推荐

  1. 【转】ionic2 返回按钮

    首先可以在 app.module.ts 文件中配置. @NgModule 中的 imports 属性的 IonicModule.forRoot 第二个参数,如下: IonicModule.forRoo ...

  2. "___gxx_personality_v0", referenced from:

    这是因为里面有用到C++ 的一些东西.所以会出现这个问题 两种解决办法. 第一种.TARGETS -> Build Phases -> Link Binary With Libraries ...

  3. jQuery.cookie应用操作

    //1.插件框架: /* * name @键 * value @值 * options @选项,包括有效期 路径 域名等 */ jQuery.cookie = function(name, value ...

  4. CSS 之 样式优先级机制

    多重样式(Multiple Styles):如果外部样式.内部样式和内联样式同时应用于同一个元素,就是使多重样式的情况. 1.一般情况下,优先级从低到高,如下: 浏览器缺省(即浏览器默认) →(外部样 ...

  5. 微软BI 之SSAS 系列 - 关于父子维度的设计

    除了之前的几篇文章中出现的时间维度,雪花型维度的设计之外还有一种比较特殊的维度 - 父子维度.父子维度特殊就特殊在它包含了一种基于递归关系(Recursive Relationship)的引用结构,  ...

  6. NetCore的控制台应用中搭建WebServer的方法

    一.新建NetCore控制台项目,并引入下列Nuget包: Microsoft.AspNetCore.StaticFiles.Microsoft.AspNetCore.Http.Microsoft.A ...

  7. WIP 005 - Implement the search result page

    Need to show the search result in a tablewalker You can show the tablewalker in the search page whic ...

  8. C#用openfiledialog文件和savefileDialog打开和保存文件

    一 打开文件 Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog ...

  9. jenkins相关默认路径

    安装完成后,有如下相关目录:(1)/usr/lib/jenkins/:jenkins安装目录,WAR包会放在这里.( 2 ) /etc/sysconfig/jenkins:jenkins配置文件,“端 ...

  10. Fix problems that block programs from being installed or removed

    Follow these steps to automatically repair issues including corrupted registry keys that block you f ...