转: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

Code
using System;
using System.Web;
using System.Web.Hosting;

namespace Simone.SharePoint.WcfService
{
    public class WCFVirtualPathProvider : VirtualPathProvider
    {
        public override string CombineVirtualPaths(string basePath, string relativePath)
        {
            return Previous.CombineVirtualPaths(basePath, relativePath);
        }

public override System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType)
        {
            return Previous.CreateObjRef(requestedType);
        }

public override bool DirectoryExists(string virtualDir)
        {
            return Previous.DirectoryExists(virtualDir);
        }

public override bool FileExists(string virtualPath)
        {
            // Patches requests to WCF services: That is a virtual path ending with ".svc"      
            string patchedVirtualPath = virtualPath;
            if (virtualPath.StartsWith("~", StringComparison.Ordinal) && virtualPath.EndsWith(".svc", StringComparison.InvariantCultureIgnoreCase))
            {
                patchedVirtualPath = virtualPath.Remove(0, 1);
            }
            return Previous.FileExists(patchedVirtualPath);
        }

public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath,
                   System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
        }

public override string GetCacheKey(string virtualPath)
        {
            return Previous.GetCacheKey(virtualPath);
        }

public override VirtualDirectory GetDirectory(string virtualDir)
        {
            return Previous.GetDirectory(virtualDir);
        }

public override VirtualFile GetFile(string virtualPath)
        {
            return Previous.GetFile(virtualPath);
        }

public override string GetFileHash(string virtualPath, System.Collections.IEnumerable virtualPathDependencies)
        {
            return Previous.GetFileHash(virtualPath, virtualPathDependencies);
        }

protected override void Initialize()
        {
            base.Initialize();
        }
    }
}

WCFVPPRegModule : IHttpModule

Code
using System;
using System.Web;
using System.Web.Hosting;

namespace Simone.SharePoint.WcfService
{
    public class WCFVPPRegModule : IHttpModule
    {
        static bool virtualPathProviderInitialized = false;
        static object virtualPathProviderInitializedSyncLock = new object();

public void Dispose()
        {
        }

public void Init(HttpApplication context)
        {
            if (!virtualPathProviderInitialized)
            {
                lock (virtualPathProviderInitializedSyncLock)
                {
                    if (!virtualPathProviderInitialized)
                    {
                        WCFVirtualPathProvider vpathProvider = new WCFVirtualPathProvider();
                        HostingEnvironment.RegisterVirtualPathProvider(vpathProvider);
                        virtualPathProviderInitialized = true;
                    }
                }
            }
        }
    }
}

如图:

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>

在该节点下添加节点:

Code
<add name="WcfVirtualPathProvider" type="Simone.SharePoint.WcfService.WCFVPPRegModule,Simone.SharePoint.WcfService, Version=1.0.0.0, Culture=neutral,PublicKeyToken=3e1c8210e1877cc0" />

如下图:

如果你不能理解,请下载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。

 

转载于:https://www.cnblogs.com/lmjob/archive/2010/08/13/1799056.html

Hosting WCF in SharePoint 2007 (Part 1) 基本部署(转)相关推荐

  1. Professional SharePoint 2007 Web Content Management Development: Building Publishing Sites with Offi

    版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版.作者信息和本声明.否则将追究法律责任. http://blog.csdn.net/topmvp - topmvp Profess ...

  2. SharePoint 2007 安装与配置

    环境 win 2003 sp2 .net 3.0 framework SQL Server 2005 SharePoint 2007 server 安装 安装windows组件 网络服务/域名系统(D ...

  3. QuickPart : 用户控件包装器 for SharePoint 2007

    用户控件包装器升级了!现在它已经支持Microsoft Office SharePoint Server 2007 Beta2,可以让我们直接将ASP.NET 2.0的用户控件直接用在SharePoi ...

  4. 一步一步SharePoint 2007系列文章目录

    一步一步SharePoint 2007之一:安装SharePoint http://tech.ddvip.com/2008-10/122535494387212.html 一步一步SharePoint ...

  5. SharePoint 2007 SDK v1.5

    SharePoint 2007 SDK 中文版 (*)中文版的目前是1.4的, 英文版的SDK有1.5版 WSS 3.0 SDK http://www.microsoft.com/downloads/ ...

  6. SharePoint 2007部署过程详细图解之一:准备

    Microsoft Office SharePoint Server 2007(简称MOSS 2007)可以构建企业门户站点,并实现团队协作.内容管理.工作流.商业智能等强大功能,是微软2007 Of ...

  7. sharepoint 2007 网站操作 显示菜单不全

    sharepoint 2007 制作的网站: 现象: 1.编辑工具栏附近出现"未将对象引用设置到对象的实例" 2.网站操作 下拉菜单 显示不全,只有创建网页, 网站设置  导致以上 ...

  8. 使用SharePoint 2007 Web Service上传文件到文档库

    SharePoint 2010中有了全新的客户端模型,给我们在客户端操作SharePoint对象提供了很大的方便,但是在SharePoint 2007中我们可以使用的方式就比较有限,Web Servi ...

  9. SharePoint 2007 Backup Strategies

    SharePoint 2007 Backup Strategies from http://www.sharepointkicks.com/ 转载于:https://www.cnblogs.com/i ...

  10. SharePoint 2007 Web Content Management 性能优化系列 前言

    相信已经有不少SharePoint Developer正在基于SharePoint 2007构建Web Content Management(WCM)应用.我们先来明确一下什么是WCM应用,典型的WC ...

最新文章

  1. Go 语言调用 python2
  2. linux常用核心命令大全(只写程序员常用的)
  3. JSP中文乱码问题解决方案
  4. 你了解机房保温棉的使用和作用吗?
  5. 大厂抢夺冬奥会“第二赛场”
  6. 中的 隐藏鼠标菜单_Mac移动隐藏删除顶部菜单栏图标教程
  7. Luogu P1091 合唱队形
  8. 项目实践精解:C#核心技术应用开发
  9. 20200314:字母异位词分组(leetcode49)
  10. 如何解决logcat TAG过长时Android studio提示错误的问题
  11. 自由软件运动与GNU项目
  12. UC浏览器 Android8.0,五大特色解析 UC浏览器8.0安卓版评测
  13. ARM架构(RISC)和x86架构(CISC)以及传统与移动CPU/GPU厂商
  14. SSM项目tomcat启动失败-Multiple Contexts have a path of “/ssm-crud“
  15. iOS音频播放之AudioQueue(一):播放本地音乐
  16. matlab画不定积分图像实例,matlab怎么画函数图像,原来是这样的
  17. 06.简书项目实战三:详情页面和登录功能实现
  18. Java学习之路 -- Java怎么学?
  19. 旅行照片剪辑--青岛篇
  20. Vue vue-router中必不可少的redirect,meta和hidden三个属性

热门文章

  1. oracle sql语句_7个维度查看oracle执行计划的sql语句执行效率
  2. mysql基础之数据库变量(参数)管理
  3. 「ZJOI2019」麻将
  4. 分布式系统理论(二):一致性协议Paxos
  5. 最大子数组问题,分治策略基础,百度面试题
  6. VB API 之 第七课 字体应用四
  7. flex invalidation 机制
  8. 【项目实施随笔】生产领料
  9. 洛谷P3369-----普通平衡树
  10. Fragment生命周期(转)