最近在研究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 的内容
<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>