Quindi, qui va ...
Crea il tuo contratto di servizio, che un'operazione che accetta un flusso per il suo unico parametro, decorare con WebInvoke come di seguito
[ServiceContract]
public interface IService1 {
[OperationContract]
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/Upload")]
void Upload(Stream data);
}
Creare il classe ...
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
}
E la configurazione, per accettare in streaming dati, e la dimensione massima
<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>
Anche nel System.Web aumentano la quantità di dati consentita in System.Web
<system.web>
<otherStuff>...</otherStuff>
<httpRuntime maxRequestLength="2000000"/>
</system.web>
Questo è solo le basi, ma consente l'aggiunta di un progresso metodo per mostrare una barra di avanzamento ajax e potresti voler aggiungere un po 'di sicurezza.
fonte
2009-09-10 19:08:11
Vedere la mia risposta qui: http://stackoverflow.com/a/21689347/67824 –
Questo collegamento funziona per me, spero che ne abbiate un'idea. http://stackoverflow.com/questions/7460088/reading-file-input-from-a-multipart-form-data-post/14514351#14514351 –