none
Streamed 模式下 The remote server returned an unexpected response: (400) Bad Request. RRS feed

  • 问题

  • 想用basicHttpBinding transferMode="Streamed" 来发送大文件(200M以内),transferMode="Streamed" 老报如题错误,改为transferMode="StreamedResponse" 却能用,不过传得小可以,用100多兆的试也不行;

    [ServiceContract]
    public interface IMultiSiteService
    {

        [OperationContract]
        bool PutMsgToQueue(Stream value);

    }

    public class MultiSiteService : IMultiSiteService
    {
        public bool PutMsgToQueue(Stream inStream)
        {
            try
            {
                MemoryStream ms = new MemoryStream();
                byte[] buffer = new byte[1024];

                while (true)
                {
                    int sz = inStream.Read(buffer, 0, 1024);
                    if (sz == 0) break;
                    ms.Write(buffer, 0, sz);
                }
                ms.Position = 0;
                byte[] msg = ms.ToArray();
                return true;
            }
            catch (Exception exp)
            {
                throw exp;
            }       
        }
    }

    server端配置如下:

    <system.serviceModel>   
        <services>
          <service name="MultiSiteService" behaviorConfiguration="ServiceBehavior">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basichttp" contract="IMultiSiteService">
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="basichttp" closeTimeout="00:10:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="524288"
             maxBufferSize="65535"  maxReceivedMessageSize="400000000" transferMode="Streamed">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
               maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None" >
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>

        <diagnostics>
          <messageLogging
               logEntireMessage="true"
               logMalformedMessages="false"
               logMessagesAtServiceLevel="true"
               logMessagesAtTransportLevel="true"
               maxMessagesToLog="3000"
               maxSizeOfMessageToLog="2000"/>
        </diagnostics>

      </system.serviceModel>

     

    客户端配置:

    <system.serviceModel>
          <bindings>
            <basicHttpBinding>
              <binding name="BasicHttpBinding_Service1" closeTimeout="00:00:30"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxBufferSize="65535" maxReceivedMessageSize="400000000"
                textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192"
                  maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                  <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                  <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
              </binding>         
            </basicHttpBinding>
          </bindings>
          <client>
            <endpoint address="http://localhost:15390/StreamWebsite/MultiSiteService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service1"
              contract="ServiceReference1.IMultiSiteService" name="BasicHttpBinding_Service1" />       
          </client>

          <diagnostics>
            <messageLogging
                 logEntireMessage="true"
                 logMalformedMessages="false"
                 logMessagesAtServiceLevel="true"
                 logMessagesAtTransportLevel="true"
                 maxMessagesToLog="3000"
                 maxSizeOfMessageToLog="2000"/>
          </diagnostics>
        </system.serviceModel>

    改了配置文件多次多处,streamed 一直不好用,有谁能帮帮忙么,谢谢~

     

    2010年12月3日 8:45

答案

  • 谢谢答复!

    http://weblogs.asp.net/jclarknet/archive/2008/02/14/wcf-streaming-issue-under-iis.aspx

    这个帖子解决我的问题了。可能我没说清楚,是IIS hosted service。

    另外 还在配置文件web.config(<system.web>标签下)中加了

        <httpRuntime executionTimeout="600" maxRequestLength="204800" useFullyQualifiedRedirectUrl="false"   minFreeThreads="8"   minLocalRequestFreeThreads="4"/>

    2010年12月6日 9:30

全部回复