SharePonit Host WCF 注意事项

1)部署一个WCF web应用到SharePoint,报以下错误:

virtualPath .... 

原来WSS的 SPVirtualPathProvider不能识别svc为后缀的WCF文件,需要重新开发一个VirtualPathProvider:

参考:Hosting WCF in SharePoint

http://blah.winsmarts.com/2008-5-Super_Easy_way_to_add_WCF_to_SharePoint_2007__wwwcodeplexcom-SPWCFSupport.aspx

codeplex上有个wsp包直接解决这个问题:

http://spwcfsupport.codeplex.com/SourceControl/ListDownloadableCommits.aspx

2)做了以上操作后,出来另一个错误: WCF配置成匿名,而IIS站点非匿名。。。

需要指定WCF的认证方式:

http://stackoverflow.com/questions/847414/sharepoint-wcf-and-anonymous-access

3) IIS host WCF时,默认情况下,WCF中的代码只能读取跟目录下的web.config,如果要读取非根下的config,

可以使用以下代码:

VirtualPathExtension extension = OperationContext.Current.Host.Extensions.Find<VirtualPathExtension>();

Configuration config = WebConfigurationManager.OpenWebConfiguration(extension.VirtualPath);

string data = config.AppSettings.Settings["UserServiceUrl"].Value;

参考:

http://blogs.msdn.com/wenlong/archive/2006/02/21/read-configuration-data-from-hosted-wcf-services.aspx

4)WCF中的代码不能访问HttpContext,不能访问除根目录以外的web.config, 但是可以配置成asp.net兼容模式,

使WCF可以拥有asp.net的所有功能:

 首先,修改web.config:

<system.serviceModel
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

然后,在WCF的service类上添加特性:

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class TaskService : ITaskService{}

参考:http://msdn.microsoft.com/en-us/library/aa702682.aspx

 后记:部署到生产环境后又出现错误信息:

: "This collection already contains an address with scheme http"

 需要修改配置文件:

<serviceHostingEnvironment>

    <baseAddressPrefixFilters>

        <add prefix="http://www.example.com"/>

    </baseAddressPrefixFilters>

</serviceHostingEnvironment>

参考:http://blog.befruit.com/2008/09/wcf-error-this-collection-already.html 

 

SharePoint 2007 as a WCF host

http://blah.winsmarts.com/2008-5-SharePoint_2007_as_a_WCF_host_-_Step_-1,_make_a_WCF_Home.aspx


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值