栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

WCF服务接受后期编码的多部分/表单数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

WCF服务接受后期编码的多部分/表单数据

所以,这里…

创建您的服务合同,该操作将接受流作为其唯一参数的操作,并使用WebInvoke装饰如下

[ServiceContract]public interface IService1 {    [OperationContract]    [WebInvoke(        Method = "POST",        BodyStyle = WebMessageBodyStyle.Bare,        UriTemplate = "/Upload")]    void Upload(Stream data);}

创建课程…

    public class Service1 : IService1 {    public void Upload(Stream data) {        // Get header info from WebOperationContext.Current.IncomingRequest.Headers        // open and depre the multipart data, save to the desired place    }

和配置,接受流数据,并且最大大小

<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>

同样在System.Web中增加System.Web中允许的数据量

<system.web>        <otherStuff>...</otherStuff>        <httpRuntime maxRequestLength="2000000"/></system.web>

这只是基础知识,但是允许添加Progress方法以显示ajax进度栏,并且您可能需要增加一些安全性。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/647598.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号