webservice for sharepoint 2010

最近在研究webservice  for sharepoint ,記錄一下

首先添加三個dll引用一個是System.ServiceModel

另一個是Microsoft.SharePoint.Client.ServerRuntime這個dll比較特殊需要通過地址添加

C:\Windows\assembly\GAC_MSIL\Microsoft.SharePoint.Client.ServerRuntime\14.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.ServerRuntime.dll

最後一個System.Runtime.Serialization.dll。

項目的結構圖,ISAPI 是sharepoint的一個映射路徑,需要添加到vs裏面,在裏面創建web.config

另外一個文件是需要創建txt文件,修改後綴名得到的文件裏面的內容

<%@ ServiceHost Debug="true" Language="C#"
Service="SharePointProject2.Service1, $SharePoint.Project.AssemblyFullName$"
CodeBehind="Service1.cs" %>這個也是需要調用的服務文件

下面是web.config 的內容

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behavior name="命名空間名.webservice文件名+Behavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="false" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <services>

      <service behaviorConfiguration="命名空間名.webservice文件名+Behavior"

          name="命名空間名.webservice文件名">

        <endpoint address="" binding="basicHttpBinding" contract="命名空間名.webservice文件接口名">

          <identity>

            <dns value="localhost" />

          </identity>

        </endpoint>

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

      </service>

    </services>

  </system.serviceModel>

</configuration>


下面就說說webservice文件怎麼創建吧,我是這樣做的,新建一個WCF的項目

創建好之後,取出裏面接口文件跟服務文件添加到創建好的sharepoint項目裏面即可。

還有一步非常重要,也是很隱蔽的地方需要修改,就是用記事本打開你解決方案在裏面添加一行代碼標紅的部分


<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{A1C9F7DB-6584-4743-A953-EA1E6375B3E3}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>ChongHongKMS</RootNamespace>
    <AssemblyName>ChongHongKMS</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{BB1F664B-9266-4fd6-B973-E1E44974B511};{14822709-B5A1-4724-98CA-57A101D1B079};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}        </ProjectTypeGuids>
    <SandboxedSolution>False</SandboxedSolution>
   <TokenReplacementFileExtensions>svc</TokenReplacementFileExtensions>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章