[英]How to Send Large File From Client To Server Using WCF?
How to Send Large File From Client To Server Using WCF in C#? 如何在C#中使用WCF从客户端向服务器发送大文件? Below the configuration code. 在配置代码下面。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="HttpStreaming_IStreamingSample"
maxReceivedMessageSize="67108864"
transferMode="Streamed">
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://localhost:4127/StreamingSample.svc"
binding="basicHttpBinding"
bindingConfiguration="HttpStreaming_IStreamingSample"
contract="StreamingSample.IStreamingSample"
name="HttpStreaming_IStreamingSample" />
</client>
</system.serviceModel>
You need to check out streaming, as Dzmitry already pointed out. 正如Dzmitry已经指出的那样,你需要检查流媒体。
In order to be able to send large files as a stream to your service, you'll need to: 为了能够将大型文件作为流发送到您的服务,您需要:
Stream
as its input parameter 创建一个接受Stream
作为其输入参数的服务方法 transferMode=StreamedRequest
创建使用transferMode=StreamedRequest
的绑定配置(在服务器和客户端上) So first off, you need a method in your service contract: 首先,您需要在服务合同中使用一种方法:
[ServiceContract]
interface IYourFileService
{
[OperationContract]
void UploadFile(Stream file)
}
Then you need a binding configuration: 然后你需要一个绑定配置:
<bindings>
<basicHttpBinding>
<binding name="FileUploadConfig"
transferMode="StreamedRequest" />
</basicHttpBinding>
</bindings>
and a service endpoint on your service using that binding configuration: 以及使用该绑定配置的服务上的服务端点:
<services>
<service name="FileUploadService">
<endpoint name="UploadEndpoint"
address="......."
binding="basicHttpBinding"
bindingConfiguration="FileUploadConfig"
contract="IYourFileService" />
</service>
</services>
and then, in your client, you need to open eg a filestream and send that to the service method without closing it. 然后,在您的客户端中,您需要打开例如文件流并将其发送到服务方法而不关闭它。
Hope that helps! 希望有所帮助!
Marc 渣
您可以查看WCF流媒体功能。
In addition to increasing readerQuota settings (mentioned above) I had to also up the maxRequestLength inside the httpRuntime attribute. 除了增加readerQuota设置(如上所述)之外,我还必须在httpRuntime属性中增加maxRequestLength。
<system.web>
<httpRuntime maxRequestLength="2097151" />
</system.web>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.