none
WCF 上传图片 Stream 异常NotSupportedException RRS feed

  • 问题

  • 客户端纯HTML的Form上传

        <form action="/FileService.svc/ajaxEndpoint/UploadImage" method="post" enctype="multipart/form-data"> 
            <input  type="file" name="FileData"/>
            <input type="submit"  />
        </form>

    服务寄宿IIS,

          </service>
          <service name="Touch_Dinner.Service.FileService"  behaviorConfiguration="BasicBehavior" >
            <endpoint address="/ajaxEndpoint" binding="webHttpBinding" bindingConfiguration="webStream"  behaviorConfiguration="AjaxBehavior" contract="Touch_Dinner.Contract.IFileService" />
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <binding name="webStream"
                   sendTimeout="00:10:00"
                   transferMode="Streamed"
                   receiveTimeout="00:10:00"
                   maxReceivedMessageSize="9223372036854775807">
            </binding>
            <binding name="webBinding" closeTimeout="00:01:00"
                       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                       bypassProxyOnLocal="false"  hostNameComparisonMode="StrongWildcard"
                       maxBufferPoolSize="524288" maxReceivedMessageSize="999999" useDefaultWebProxy="true"
                       allowCookies="false">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
          </webHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="BasicBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <!--适用于所有Web的Ajax-->
            <behavior name="AjaxBehavior">
              <webHttp/>
            </behavior>
            <!--适用于Asp.net的Ajax-->
            <behavior name="Asp.netAjaxBehavior">
              <enableWebScript/>
            </behavior>
          </endpointBehaviors>

    契约与实现

        [ServiceContract]
        public interface IFileService
        {
            [OperationContract]
            void UploadImage(Stream FileData);
        }
    
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class FileService:IFileService
        {
            [WebInvoke(Method="*",BodyStyle=WebMessageBodyStyle.Bare)]
            public void UploadImage(Stream FileData)
            {
                long l = FileData.Length;
                return;
            }
        }

    测试图片只有10几k,

    异常

    Stream

    Length = “FileData.Length”引发了“System.NotSupportedException”类型的异常

    如何解决,无法接收到流



    • 已编辑 linsage1 2013年2月14日 6:42
    2013年2月14日 2:02

答案