青林园

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

SharePoint文档库通过WCF服务,采用

多线程技术上传大文件解决方案(初稿)

 

一、首先要有SharePoint平台(这个有点费话之嫌)

    这个我想大家都应该有了。

二、按照Kaneboy提供的Office SharePoint Server 2007 External Binary Storage解决方案配置好,使网站集能将文档库文件存储在指定的磁盘目录中,而不是数据库。

         K老大有详细的介绍,我就不多说了。

设置:http://blog.joycode.com/kaneboy/archive/2008/06/19/115154.aspx

组件:http://blog.joycode.com/kaneboy/archive/2008/06/23/115159.aspx

三、配置SharePoint网站集,使其能承载WCF服务

         这个网上有(费话!要不我也玩不转),但我还是详细的介绍一下,方便大家。

1.在网站集根目录(如:C:\inetpub\wwwroot\wss\VirtualDirectories\80)下创建一个目录_wcf(这个是我创建的,别的也行)

2.IIS管理器中点击此目录,并设置身份验证,如图:(以Window Server 2008为例,IIS6应该差不多)将匿名身份验证设置为:已启用

 

3.更改网站集根目录下的web.config文件,如图:为所创建目录的解析添加配置信息。

<httpModules>

      <clear />

      <add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

      <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />

      <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />

      <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />

      <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />

      <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />

      <!-- <add name="Session" type="System.Web.SessionState.SessionStateModule"/> -->

      <add name="Session" type="System.Web.SessionState.SessionStateModule" />

      <!--2008109日添加,主要为SharePoint添加WCF提供虚拟路径解析-->

      <add name="WCFVirtualPathProvider" type="NIC.SharePoint.WCFService.WCFVirtualPathProviderRegModule,NIC.SharePoint.WCFService" />

      <add name="PublishingHttpModule" type="Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

    </httpModules>

此配置信息所引用的程序集(生成的程序集放在根目录下的bin目录中)的源代码(主要是提供程序类WCFVirtualPathProvider和提供程序的注册类WCFVirtualPathProviderRegModule)我将在第四步中一并提供(也是网上找的,出处忘记了,在此就不链接和声明了,下同)

这样,你应该已经可以在SharePoint网站集中承载WCF服务了。

四、创建、发布、配置、引用WCF服务

1.首先创建一个WCF服务库项目

2.然后删除自动生成的一个服务,就是将IService1.csService1.cs两个文件删除。

3.app.config文件中与IService1相关的信息删除,留下如下内容:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.web>

<compilation debug="true" />

</system.web>

    <system.serviceModel>

        <behaviors>

            <serviceBehaviors>               

            </serviceBehaviors>

        </behaviors>

        <services>

        </services>

    </system.serviceModel>

</configuration>

 

4.接着添加一个WCF服务 FileTransfer,这时,IDE会自动为你添加一个与此服务相关的配置,变为:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.web>

<compilation debug="true" />

</system.web>

    <system.serviceModel>

        <behaviors>

            <serviceBehaviors>

                <behavior name="NIC.SharePoint.WCFService.FileTransferBehavior">

                    <serviceMetadata httpGetEnabled="true" />

                    <serviceDebug includeExceptionDetailInFaults="false" />

                </behavior>

            </serviceBehaviors>

        </behaviors>

        <services>

            <service behaviorConfiguration="NIC.SharePoint.WCFService.FileTransferBehavior"

                name="NIC.SharePoint.WCFService.FileTransfer">

                <endpoint address="" binding="wsHttpBinding" contract="NIC.SharePoint.WCFService.IFileTransfer">

                    <identity>

                        <dns value="localhost" />

                    </identity>

                </endpoint>

                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

            </service>

        </services>

    </system.serviceModel>

</configuration>

 

5.此时如果你进行调试会有下面的界面,表明你已经创建了一个服务。

6.创建一个.svc文件和配置文件

_wcf目录下创建FileTransfer.svc文件(可用记事本创建),里面添加如下内容:

<%@ Assembly Name="NIC.SharePoint.WCFService"%>

<%@ ServiceHost Language="C#" Service="NIC.SharePoint.WCFService.FileTransfer" %>

_wcf目录下创建web.config配置文件,里面添加如下内容:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

     <system.web>

         <httpRuntime maxRequestLength="65536"></httpRuntime>

     </system.web>

     <system.serviceModel>

         <bindings>

              <wsHttpBinding>

                   <binding name="WSHttpBinding_IFileTransfer" messageEncoding="Mtom" maxReceivedMessageSize="65536">

                       <security mode="None">

                            <transport clientCredentialType="Windows" proxyCredentialType="None"

                            realm="" />

                            <message clientCredentialType="Windows" negotiateServiceCredential="true"

                            establishSecurityContext="true" />

                       </security>

                   </binding>

              </wsHttpBinding>

              <basicHttpBinding>

                   <binding name="HttpStreaming" maxReceivedMessageSize="67108864"

                             transferMode="Streamed"/>

              </basicHttpBinding>

         </bindings>

         <services>

              <service

                   name="NIC.SharePoint.WCFService.FileTransfer"

                   behaviorConfiguration="FileTransferBehavior">

                   <endpoint address=""

                              binding="wsHttpBinding"

                              bindingConfiguration="WSHttpBinding_IFileTransfer"

                              contract="NIC.SharePoint.WCFService.IFileTransfer" />

                   <endpoint address="mex"

                              binding="mexHttpBinding"

                              contract="IMetadataExchange" />

              </service>

         </services>

 

         <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->

         <behaviors>

              <serviceBehaviors>

                   <behavior name="FileTransferBehavior">

                       <serviceMetadata httpGetEnabled="True"/>

                       <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />

 

                   </behavior>

              </serviceBehaviors>

         </behaviors>

     </system.serviceModel>

</configuration>

这其中的内容其实就是将原来创建服务时生成的app.config文件的内容增加了传输绑定的内容和一个传输设置。

7.接着,将你生成的服务程序集(我的是NIC.SharePoint.WCFService.dll)复制到bin目录。如此一来,服务算是创建、发布和配置好了。你可通过IE来访问你的服务了

8.最后,创建一个客户端程序通过在项目上右击,“添加服务引用”来完成我们的项目。(你也可用svcutil工具来引用,具体的关于WCFMSDN里都有的)。

至于以后如果做的,详细的就看代码了。

 代码这里有,我不知如何发代码,只能链接了http://bbs.msiw.net/showtopic-463-1.html#1553

五、最后要说的

1.         以上解决方案只是初步的,后续我会不断的完善。

2.         这其中我已经考虑好了一点,就是在上传之前进行文件大小的判断,如果达到一定值才会通过这种方式上传并存储在磁盘上,如果文件较小则通过普通传递方式上传到数据库中。这里面涉及到K老大对扩展存储解决方案的内容,可惜他没有共享核心代码,我现现在还不知实现的机制。

3.         另外这里面的传输块的大小限制在16K以下,我看还有其他解决方法没。

4.         参考和引用的主要内容http://www.codeproject.com/KB/XML/MTOMWebServices.aspx

5.   昨天测试了一下,同时发两个4G的,最后发到了2.7G,因为超时而中止,时间是可以在配置文件中设置的,这不是问题

posted on 2008-12-10 09:34  青林一霸  阅读(1667)  评论(5编辑  收藏  举报