Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html WCF服务接受后期编码的多部分/表单数据_Html_Wcf_Http - Fatal编程技术网

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

Html WCF服务接受后期编码的多部分/表单数据,html,wcf,http,Html,Wcf,Http,是否有人知道,或者最好有一个WCF服务的例子,该服务将接受表单后编码多部分/表单数据,即从网页上传文件 我在谷歌上一无所获 Ta,Ant我不知道您在这里想要完成什么,但是基于“经典”SOAP的WCF中没有内置的支持来捕获和处理表单post数据。你得自己做 另一方面,如果您谈论的是基于REST的WCF和webHttpBinding,那么您肯定会有一个用[WebInvoke()]属性修饰的服务方法,该属性将由HTTP POST方法调用 [WebInvoke(Method="POST", Ur

是否有人知道,或者最好有一个WCF服务的例子,该服务将接受表单后编码
多部分/表单数据
,即从网页上传文件

我在谷歌上一无所获


Ta,Ant

我不知道您在这里想要完成什么,但是基于“经典”SOAP的WCF中没有内置的支持来捕获和处理表单post数据。你得自己做

另一方面,如果您谈论的是基于REST的WCF和webHttpBinding,那么您肯定会有一个用[WebInvoke()]属性修饰的服务方法,该属性将由HTTP POST方法调用

    [WebInvoke(Method="POST", UriTemplate="....")]
    public string PostHandler(int value)
URI模板将定义要在HTTP POST应该去的地方使用的URI。你必须把它连接到你的ASP.NET表单上(或者你用来写这篇文章的任何东西)

要了解REST风格WCF的精彩介绍,请查看Aaron Skonnard关于WCF REST初学者工具包的介绍以及如何使用它

马克

那么,接下来

创建您的服务契约,该契约是一个接受流作为其唯一参数的操作,用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 decode 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>

...

这只是基础,但允许添加一个进度方法来显示ajax进度条,您可能需要添加一些安全性。

Hi Marc,我想要一个restful wcf服务,它可以接受来自html表单的发布数据,该表单中有一个[input type=file/]。我已经能够在没有文件的情况下发布表单。我不希望客户端应用程序只是浏览器,因此我无法将文件转换为字节流,这将是一个多部分/表单数据http POST如何删除与流一起发送的所有垃圾,如:内容处置:,内容类型:等。。。我正试图让这个工作的图像。还有,为什么合同定义中不能包含任何其他参数?请看我的回答:此链接对我有效,我希望您能从中了解一些信息。