0

I created a web service to upload files over http but on my first try, it is failing.

My web service is running on my local computer's IIS 7, under ASP.NET 4 Integrated App Pool. Here this is my web service's 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>

This is the web.config file of the client;

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

Here is the error I receive;

The remote server returned an error: (400) Bad Request.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.

Source Error:

Line 120:
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] Line 121:
FileUploadWcfServiceClient.TransferService.UploadFileResponse FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(FileUploadWcfServiceClient.TransferService.RemoteFileInfo request) { Line 122: return base.Channel.UploadFile(request); Line 123: } Line 124:

Source File: C:\Apps\FileUploadWcfService\FileUploadWcfServiceClient\Service References\TransferService\Reference.cs Line: 122

Stack Trace:

[WebException: The remote server returned an error: (400) Bad Request.] System.Net.HttpWebRequest.GetResponse() +6111059
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) +9456095
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(RemoteFileInfo request) +0
FileUploadWcfServiceClient.TransferService.TransferServiceClient.FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(RemoteFileInfo request) in C:\Apps\FileUploadWcfService\FileUploadWcfServiceClient\Service References\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(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

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

The file that I am trying to upload is 217 KB so I am guessing the file size is not the problem here.

What do you think causing the error?

4

0 回答 0