WCF服务将大文件上传到ftp服务器

时间:2013-09-25 06:01:47

标签: c# wcf windows-phone-8 web-config ftpwebrequest

我正在开发一个Windows手机应用程序,它将图像zip文件上传到 ftp服务器。但是我无法上传它。它出错远程服务器未找到

以下是我的 WCF 应用 web.config

<?xml version="1.0"?>
<configuration>

 <appSettings>
       <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="409600" />   
</system.web>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <!--<binding maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:10:00" closeTimeout="00:10:00">
      <security mode="None" />
    </binding>-->
    <binding closeTimeout="01:30:00" 
      openTimeout="01:30:00" receiveTimeout="01:30:00" sendTimeout="01:30:00" 
      maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646">
      <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
        maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" /> 
      <security mode="None">             
      </security>
    </binding>    
  </basicHttpBinding>    
</bindings>   

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
 <protocolMapping>
    <add binding="basicHttpsBinding"  scheme="https"/>
 </protocolMapping>    
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
 <directoryBrowse enabled="true"/>
</system.webServer>

这是我的 ServiceReferences.ClientConfig

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" closeTimeout="01:10:00"
                    openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://xxx.xx.x.xxx/WebService/Service1.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="MyService.IService1" name="BasicHttpBinding_IService1" />
    </client>
</system.serviceModel>

我创建了两个项目,一个是windows phone应用程序,第二个是wcf应用程序。我正在向wcf服务器发送大型 byte [] 数组,这会产生错误远程服务器Notfound 。当byte[] size较小时它可以很好地工作,但是当尺寸很大时它会失败。我听说我们可以发送非常大的文件到大约4gb附近的wcf服务。那我错了?我在 web.config 中有什么变化吗?我在本地计算机上对{strong> IIS 进行了hosted我的wcf服务。

1 个答案:

答案 0 :(得分:0)

要通过wcf发送大数据,您有两种选择:

  1. 您可以手动将数据分成多个部分(例如,从文件中读取2Kb)并分别传输每个部分。在服务器端,您可以将每个部分保存在临时文件中。这种方法需要一些编码(例如部分的控制顺序)。

  2. 另一种选择是使用 transferMode =“Streamed”,但此模式有一些限制。

  3. <强>更新

    如果由于某些原因无法使用流式模式,您可以在服务中创建一些方法:

    string BeginSendFile();
    

    此方法必须生成id(例如Guid)并将其返回给客户端。此外,服务可以使用此名称在临时存储中创建文件。

    void SendFilePortion(string id, byte[] data);
    

    您调用此方法并传输一些数据。服务器可以通过id找到临时文件并将数据写入其中。

    void EndSentFile(string id, string originalName);
    

    在传输所有数据时调用此方法以重命名临时文件并将其替换为非临时存储。

相关问题