简体   繁体   中英

WCF service upload large file to ftp server

I am developing one windows phone application which upload images zip file to ftp server . But I can't upload it. It gives an error Remote server Not found

Here is my WCF application 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>

Here is my 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>

I have create two project one is windows phone application, second is wcf application. I am sending large byte[] array to wcf server which gives an error Remote server Notfound . It works perfectly when the byte[] size is small but fails when the size is large. I heard that we can send very large file to wcf service near about 4gb. Then where I was wrong? Is there any change I have to do in web.config ? I have hosted my wcf service to IIS on local machine.

For sending large data over wcf you have two options:

  1. You may manually break your data into pieces (or read by 2Kb from file for example) and transfer each piece separately. At server side you may save each piece in temp file. This method require some coding (control order of portions for example).

  2. Another option is using transferMode="Streamed" , but this mode have some restrictions.

Update

If you can't use Streamed mode for some reasons, you may create in your service some methods:

string BeginSendFile();

This method must gererate id (Guid for example) and return it to client. Also service may create a file in temporary storage with this name.

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

You call this method and transfer a little data. Server may find temp file by id and write data to it.

void EndSentFile(string id, string originalName);

Call this method when transfer all data to rename your temp file and replace it in non-temp storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM