我能';t使用wcf上载大于45 KB的文件

我能';t使用wcf上载大于45 KB的文件,wcf,Wcf,我的代码适用于小于45 Kb的文件,但当我上载文件时,会出现以下错误: 远程服务器返回错误:(400)请求错误 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源 异常详细信息:System.Net.WebException:远程服务器返回错误:(400)请求错误 源错误: Line 120: [System.ComponentModel.EditorBrowsableAttribute(System.ComponentMod

我的代码适用于小于45 Kb的文件,但当我上载文件时,会出现以下错误:

远程服务器返回错误:(400)请求错误

描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.Net.WebException:远程服务器返回错误:(400)请求错误

源错误:

Line 120:        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
Line 121:        WebApplication2.ServiceReference1.uploadfileResponse WebApplication2.ServiceReference1.IService1.uploadfile(WebApplication2.ServiceReference1.RemoteFileInfo request) {
Line 122:            return base.Channel.uploadfile(request);
Line 123:        }
Line 124:        
源文件:
C:\Users\KHALED\documents\visualstudio 2010\Projects\WcfServicefiles\WebApplication2\Service References\servicerence1\Reference.cs

电话:122

堆栈跟踪:

[WebException: The remote server returned an error: (400) Bad Request.]
   System.Net.HttpWebRequest.GetResponse() +6115427
   System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48

[ProtocolException: The remote server returned an unexpected response: (400) Bad Request.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9455983
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   WebApplication2.ServiceReference1.IService1.uploadfile(RemoteFileInfo request) +0
   WebApplication2.ServiceReference1.Service1Client.WebApplication2.ServiceReference1.IService1.uploadfile(RemoteFileInfo request) in C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Service References\ServiceReference1\Reference.cs:122
  WebApplication2._Default.Button2_Click(Object sender, EventArgs e) in C:\Users\KHALED\documents\visual studio 2010\Projects\WcfServicefiles\WebApplication2\Default.aspx.cs:38
  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
这是我的服务器网络配置代码:

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

  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
     <httpRuntime maxRequestLength="2097151"
    useFullyQualifiedRedirectUrl="true"
               executionTimeout="14400"

                 />
  </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SomeServiceServiceBehavior">
          <!--   To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="6553600"/>
          <!-- 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 -->

        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647"
        maxNameTableCharCount="2147483647"/>
          <security mode="None">
            <transport clientCredentialType="Ntlm"/>
          </security>
        </binding>            
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="Service1.svc.cs"  >
        <endpoint address="" binding="basicHttpBinding"
                  bindingConfiguration="Service1"
                  contract="IService1" >

        </endpoint>



      </service>

    </services>


    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>

</configuration>

这是客户端的web.config

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
      <httpRuntime maxRequestLength="2097150"      />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>

        <behavior  name="SomeServiceServiceBehavior">
          <dataContractSerializer maxItemsInObjectGraph="6553600"/>

        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior  name="SomeServiceServiceBehavior">
          <dataContractSerializer maxItemsInObjectGraph="6553600"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" closeTimeout="04:01:00"
          openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
     <endpoint address="http://localhost/WcfServicefiles/Service1.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
        contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>
</configuration>


试试下面这个例子:

服务器web.config的下面部分

  <services>
      <service name="Service1.svc.cs"  >
        <endpoint address="" binding="basicHttpBinding"
                  bindingConfiguration="Service1"
                  contract="IService1" >
        </endpoint>
      </service>
    </services>

具有错误属性的某些值。服务元素的name属性值需要为namespace.Service1,类似地,endpoint元素的contract属性值需要为namespace.IService1,如下所示:

  <services>
      <service name="<namespace>.Service1"  >
        <endpoint address="" binding="basicHttpBinding"
                  bindingConfiguration="Service1"
                  contract="<namespace>.IService1" >
        </endpoint>
      </service>
    </services>

只需替换为Service1类的名称空间。这应该行得通