2014-09-25 59 views
1

使用Kendo UI上傳控件,如何獲取wcf服務操作中上傳的文件。提供了saveUrl選項和我的wcf方法,但不知道如何獲取上傳的文件細節。仍然無法理解saveField選項的用途。請建議。Kendo UI上傳控件 - saveField和saveUrl

////服務聲明 公共接口ISampleWcf { [OperationContract的] [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped,ResponseFormat = WebMessageFormat.Json)] 空隙的DoWork();

 [OperationContract] 
     [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] 
     void SaveAttachments(List<HttpPostedFileBase> files); 
    } 

////服務實現。

public class SampleWcf : ISampleWcf 
    { 
     public void DoWork() 
     { 
     } 

     public void SaveAttachments(List<HttpPostedFileBase> files) 
     { 
      //HttpPostedFile file; 
      var current = System.Web.HttpContext.Current; 
      if(current != null) 
      { 
       var f = current.Request["files"]; 
      } 
     } 
    } 

//// jQuery腳本

$("#files").kendoUpload({ 
        async: { 
         saveUrl: "SampleWcf.svc/SaveAttachments", 
         saveField: "customSaveField", 
         autoUpload: true 
        }, 
        success: onSuccess, 
        error: onError 
       }); 

       function onSuccess(e) { 
        alert('s'); 
       } 

       function onError(e) { 
        // Array with information about the uploaded files 
        var files = e.files; 

        if (e.operation == "upload") { 
         alert("Failed to upload " + files.length + " files"); 
        } 
       } 

/////Web.Config文件

<?xml version="1.0"?> 


<configuration> 
    <system.web> 
     <compilation debug="true" targetFramework="4.5" /> 
     <httpRuntime targetFramework="4.5" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="serviceBehavior" name="WebApplication1.SampleWcf"> 
     <endpoint address="" contract="WebApplication1.ISampleWcf" behaviorConfiguration="webSupport" 
        binding="webHttpBinding" bindingConfiguration="webServiceBinding" name="jsonEndPoint"> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="webSupport"> 
      <webHttp /> 
     </behavior> 

     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="serviceBehavior"> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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> 
    <bindings> 
     <webHttpBinding> 
     <binding name="webServiceBinding" maxBufferSize="2147483647" 
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> 
      <readerQuotas maxDepth="34" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="None" /> 
     </binding> 


     </webHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment> 
    </system.serviceModel> 

</configuration> 
+0

任何建議請 – Mallikarjun 2014-09-26 09:09:44

回答

0

的 「異步saveField」 的值爲 「customSaveField」。然後它應該與您的SaveAttachments參數的名稱相匹配。

public void SaveAttachments(List<HttpPostedFileBase> customSaveField)