前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SharePoint 2013创建WCF REST Service

SharePoint 2013创建WCF REST Service

作者头像
用户1161731
发布2018-01-11 13:21:04
8770
发布2018-01-11 13:21:04
举报
文章被收录于专栏:木宛城主木宛城主

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
代码语言:javascript
复制
<%@ 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是否成功部署,需要实现契约接口:

 创建用于测试的契约接口:

代码语言:javascript
复制
  [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
    }

 接着实现契约接口,也就是我们的服务:

代码语言:javascript
复制
 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
  • 8.最后,修改Config文件
代码语言:javascript
复制
<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方面的知识。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-12-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SharePoint 中 创建WCF Service
  • 小结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档