[英]WCF service upload large file to ftp server
我正在開發一個Windows Phone應用程序,它將圖像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應用程序。 我正在將大byte []數組發送到wcf服務器,這將導致錯誤遠程服務器Notfound 。 當byte[] size
較小時,它可以完美地工作,但是當大小較大時,它會失敗。 聽說我們可以將非常大的文件發送到4GB附近的wcf服務。 那我哪里錯了? 我在web.config中需要做任何更改嗎? 我已經將wcf服務hosted
到本地計算機上的IIS 。
要通過wcf發送大數據,您有兩種選擇:
您可以手動將數據分成多個部分(例如,從文件中以2Kb讀取),然后分別傳輸每個部分。 在服務器端,您可以將每個片段保存在臨時文件中。 該方法需要一些編碼(例如,部分的控制順序)。
另一種選擇是使用transferMode =“ Streamed” ,但是此模式有一些限制。
更新資料
如果由於某些原因無法使用流模式,則可以在服務中創建一些方法:
string BeginSendFile();
此方法必須使id(例如,Guid)生效,並將其返回給客戶端。 服務也可以使用此名稱在臨時存儲中創建文件。
void SendFilePortion(string id, byte[] data);
您調用此方法並傳輸一些數據。 服務器可能會通過ID查找臨時文件並將數據寫入其中。
void EndSentFile(string id, string originalName);
傳輸所有數據以重命名臨時文件並將其替換到非臨時存儲中時,請調用此方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.