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

 

转载:http://www.cnblogs.com/jianyi0115/archive/2009/05/19/1460554.html

 

posted @ 2010-07-08 10:55  chris_thanks  阅读(321)  评论(0编辑  收藏  举报