[英]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.