使用WCF传输大数据的问题

时间:2010-09-08 08:10:58

标签: wcf streaming

您好我终于创建了一个小型上传wcf服务。我可以在我的电脑上传输小图像,但我尝试传输一首mp3歌曲以获得更大的数据。它有一个“400坏请求”例外。我不知道发生了什么。我正在流式传输数据,并在网上找到了很多资源,但似乎没有任何工作,这就是我所拥有的服务web.config:

 <?xml version="1.0"?>
<configuration>

  <system.web>
    <httpRuntime maxRequestLength="67108864"/>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="67108864">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
        </binding>
        <!--<binding name="ExampleBinding" transferMode="Streamed" messageEncoding="Mtom" />-->
      </basicHttpBinding>

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

这是我的客户app.config。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMediaServer" closeTimeout="00:10:00"
                    openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
                    useDefaultWebProxy="true">
                  <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:49689/MediaServer.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IMediaServer" contract="mediaServer.IMediaServer"
                name="BasicHttpBinding_IMediaServer" />
        </client>
    </system.serviceModel>
</configuration>

据我所知,我应该能够接收至少64Mb的数据,而我尝试传输的数据大约是4Mb。任何人都可以指出我在配置中的错误是正确的方向(至少我怀疑错误在我的配置中)

修改 这些是我的合同:

[ServiceContract]
    public interface IMediaServer
    {

        [OperationContract]
        void UploadData(UploadFile data);
    }

[MessageContract]
    public class UploadFile
    {
        public UploadFile() { }

        [MessageHeader]
        public string FileName { get; set; }

        [MessageHeader]
        public string Type { get; set; }

        [MessageHeader]
        public string AccountName { get; set; }

        [MessageBodyMember]
        public Stream data { get; set; }
    }

1 个答案:

答案 0 :(得分:1)

您的客户端未配置为使用Streaming。将客户端配置中的传输模式更改为Streamed。同样在您的服务配置中尝试删除绑定名称。目前您正在使用默认端点端点,该端点使用默认绑定配置=没有名称的配置。