Vì vậy, ở đây đi ...
Tạo hợp đồng dịch vụ của bạn mà một hoạt động mà chấp nhận một dòng cho tham số duy nhất của nó, trang trí với WebInvoke như sau
[ServiceContract]
public interface IService1 {
[OperationContract]
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/Upload")]
void Upload(Stream data);
}
Tạo lớp ...
public class Service1 : IService1 {
public void Upload(Stream data) {
// Get header info from WebOperationContext.Current.IncomingRequest.Headers
// open and decode the multipart data, save to the desired place
}
Và cấu hình, để chấp nhận luồng dữ liệu và kích thước tối đa
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebConfiguration"
maxBufferSize="65536"
maxReceivedMessageSize="2000000000"
transferMode="Streamed">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Sandbox.WCFUpload.Web.Service1Behavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Sandbox.WCFUpload.Web.Service1" behaviorConfiguration="Sandbox.WCFUpload.Web.Service1Behavior">
<endpoint
address=""
binding="webHttpBinding"
behaviorConfiguration="WebBehavior"
bindingConfiguration="WebConfiguration"
contract="Sandbox.WCFUpload.Web.IService1" />
</service>
</services>
</system.serviceModel>
Cũng trong System.Web tăng số lượng dữ liệu được cho phép trong System.Web
<system.web>
<otherStuff>...</otherStuff>
<httpRuntime maxRequestLength="2000000"/>
</system.web>
Đây chỉ là những điều cơ bản, nhưng cho phép việc bổ sung một Progress để hiển thị thanh tiến trình ajax và bạn có thể muốn thêm một số bảo mật.
Nguồn
2009-09-10 19:08:11
Xem câu trả lời của tôi tại đây: http://stackoverflow.com/a/21689347/67824 –
Liên kết này có tác dụng với tôi, tôi hy vọng bạn sẽ nhận được một số ý tưởng từ nó. http://stackoverflow.com/questions/7460088/reading-file-input-from-a-multipart-form-data-post/14514351#14514351 –