zoukankan      html  css  js  c++  java
  • 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 FilesCommon FilesMicrosoft SharedWeb Server Extensions15isapi 文件夹中,对应于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方面的知识。

  • 相关阅读:
    Payload Header到底是什么
    usb bulk传输和同步传输
    Video streaming interface 带宽的选择
    Methyl-SeqDNA的甲基化图谱|DNase I-Seq|ChIP-Seq|3C-Seq|
    连词词组|relax|brings about a rise in|Chance are (high)that|Have no clue|Be passionate about|Tedious|overwhelmed by piles of
    body书写总框架
    单个body|简单解释|复杂解释|反面解释
    TS写法
    saturates|meteoric|enclose|marooned|predators|Pioneer community|salinization|condenser|embodied
    否定事实信息题
  • 原文地址:https://www.cnblogs.com/OceanEyes/p/how-to-create-wcf-rest-service-in-sharepoint-2013.html
Copyright © 2011-2022 走看看