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

时间:2011-07-28 08:59:00

标签: asp.net wcf iis bad-request wcf-streaming

我创建了一个通过http上传文件的Web服务,但是在我第一次尝试时,它失败了。

我的网络服务在我的本地计算机的IIS 7上运行,位于ASP.NET 4集成应用程序池下。这是我的web服务的web.config;

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

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

  <system.serviceModel>

    <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>

        <behavior name="TransferServiceBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceThrottling maxConcurrentCalls="500"
                             maxConcurrentSessions="500" maxConcurrentInstances="500" />  
        </behavior>

      </serviceBehaviors>

    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="TransferService" maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>

      <service behaviorConfiguration="TransferServiceBehavior" name="TransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransferService"
                contract ="ITransferService">
        </endpoint>
      </service>

    </services>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

  </system.serviceModel>

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <system.web>
    <!--<httpRuntime maxRequestLength="2097151" />-->
    <httpRuntime maxRequestLength="2097151" 
                 useFullyQualifiedRedirectUrl="true" executionTimeout="14400"   />
  </system.web>

</configuration>

这是客户端的web.config文件;

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

    <system.serviceModel>

        <bindings>
            <basicHttpBinding>
              <binding name="BasicHttpBinding_ITransferService" 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:81/TransferService.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_ITransferService" contract="TransferService.ITransferService"
                name="BasicHttpBinding_ITransferService" />
        </client>

    </system.serviceModel>
</configuration>

这是我收到的错误;

  

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

     

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

     

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

     

来源错误:

     

第120行:
  [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]   第121行:
  FileUploadWcfServiceClient.TransferService.UploadFileResponse   FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(FileUploadWcfServiceClient.TransferService.RemoteFileInfo   请求){第122行:返回   base.Channel.UploadFile(请求);第123行:}第124行:

     

源文件:   C:\ APPS \ FileUploadWcfService \ FileUploadWcfServiceClient \服务   参考文献\ TransferService \ Reference.cs行:122

     

堆栈追踪:

     

[WebException:远程服务器返回错误:(400)错误   请求。] System.Net.HttpWebRequest.GetResponse()+ 6111059
  System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(时间跨度   超时)+48

     

[ProtocolException:远程服务器返回了意外的响应:   (400)不良请求。]
  System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天   reqMsg,IMessage retMsg)+9456095
  System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培;   msgData,Int32类型)+345
  FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(RemoteFileInfo   请求)+0
  FileUploadWcfServiceClient.TransferService.TransferServiceClient.FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(RemoteFileInfo   请求)   C:\ APPS \ FileUploadWcfService \ FileUploadWcfServiceClient \服务   参考\ TransferService \ Reference.cs:122
  FileUploadWcfServiceClient.Default.Button1_Click(Object sender,   EventArgs e)in   C:\ APPS \ FileUploadWcfService \ FileUploadWcfServiceClient \ Default.aspx.cs:85   System.Web.UI.WebControls.Button.OnClick(EventArgs e)+118
  System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串   eventArgument)+112
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串   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(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   5563

     

版本信息:Microsoft .NET Framework版本:4.0.30319;   ASP.NET版本:4.0.30319.225

我要上传的文件是217 KB,所以我猜这里的文件大小不是问题。

您认为导致错误的原因是什么?

0 个答案:

没有答案