2014-09-25 144 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)