转:http://www.cnblogs.com/windbell/archive/2010/07/27/1265074.html
注:本文讲述的是*.svc服务放到_layouts目录下,如果不放到_layouts目录下,直接在根目录下新建一个文件夹(例:/test),然后再把服务放到该目录下,则第5步可以省略
关于为什么要在SharePoint中应用WCF技术,我会在后续中说明。这一篇主要的话题就是如何在SharePoint中架设WCF服务。
1、在VS2008中建立WCF服务应用程序:
打开VS2008,框架选择.Net Framewrk 3.0,项目类型选择web,新建WCF服务应用程序。
2、为WCF编写Virtual Path Provider ,并在SharePoint中注册
WCFVirtualPathProvider : VirtualPathProvider
}
}
}
WCFVPPRegModule : IHttpModule
}
}
}
}
}
}
如图:
PS:因为风铃想把WCF放在_layouts文件夹下,所以涉及到路径中会出现"~"。具体的请参见Discover Significant Developer Improvements In SharePoint Services中Integration with ASP.NET 2.0,以及VirtualPathProvider。
3、为项目强命名,并编译(F5)。
4、配置web.config
打开你想部署WCF的端口下的web.config,即经典目录C:\inetpub\wwwroot\wss\VirtualDirectories\[端口]\web.config。找到这个节点:<configuration><system.web><httpModules>
在该节点下添加节点:
如下图:
如果你不能理解,请下载reflector,察看你的dll信息。
打开你VS项目中的web.config复制<system.serviceModel>节点,粘贴到sharepoint中web.config中
如图:项目中web.config
sharepoint中web.config
5、部署WCF
以80端口为例:
打开经典12目录(C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\)
将TEMPLATE文件夹下的LAYOUTS文件夹复制到网站应用程序目录(C:\inetpub\wwwroot\wss\VirtualDirectories\80)下。
打开IIS,将SharePoint - 80站点下的_layouts虚拟目录的物理路径由C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\template\layouts改为C:\inetpub\wwwroot\wss\VirtualDirectories\80\LAYOUTS。
在80目录下的LAYOUTS中建立WcfService文件夹。
在vs项目中,右键Service1.svc,选择查看标记。去掉CodeBehind="Service1.svc.cs"
将Service1.svc放置在WcfService文件夹中。将Simone.SharePoint.WcfService.dll放置在80目录下的bin中。
PS:"Service1.svc"、"Simone.SharePoint.WcfService.dll"均为风铃在WCF范例中的名称。
6、测试WCF服务
在另外一台机器上新建一个控制台应用程序。建议用VS2008。