Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wcf

I am getting this exception when trying to access a wcf web service.

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

Server Binding Information

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="wcfSmartConnect" closeTimeout="10:01:00" 
                  maxBufferSize="104857600" maxBufferPoolSize="104857600" 
                  maxReceivedMessageSize="104857600" openTimeout="10:01:00"
                  receiveTimeout="10:10:00" sendTimeout="10:01:00"
                  messageEncoding="Mtom" transferMode="StreamedRequest">
            <readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
                          maxArrayLength="104857600" maxBytesPerRead="104857600" 
                          maxNameTableCharCount="104857600" />
         </binding>
      </basicHttpBinding>
   </bindings>
   <services>
      <service name="WcfSmartConnect.Service1"
               behaviorConfiguration="WcfSmartConnect.Service1Behavior">
         <endpoint 
               address="" 
               binding="basicHttpBinding" 
               bindingConfiguration="wcfSmartConnect"
               contract="WcfSmartConnect.IService1">
            <identity>
               <dns value="localhost" />
            </identity>
         </endpoint>
         <endpoint 
               address="mex" 
               binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
  </services>
  <behaviors>
      <serviceBehaviors>
           <behavior name="WcfSmartConnect.Service1Behavior">
            <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
   </behaviors>
</system.serviceModel>

Client Binding Information

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="wcfSmartConnect" closeTimeout="10:01:00" 
                  maxBufferSize="104857600" maxBufferPoolSize="104857600" 
                  maxReceivedMessageSize="104857600" openTimeout="10:01:00" 
                  receiveTimeout="10:10:00" sendTimeout="10:01:00" 
                  messageEncoding="Mtom" transferMode="StreamedRequest">
             <readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
                           maxArrayLength="104857600" maxBytesPerRead="104857600" 
                           maxNameTableCharCount="104857600" />
         </binding>
      </basicHttpBinding>
      <wsHttpBinding>
          <binding name="WSHttpBinding_IService11" closeTimeout="01:00:00"
                   openTimeout="01:00:00" receiveTimeout="01:00:00" 
                   sendTimeout="01:00:00" bypassProxyOnLocal="false" 
                   transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                   maxBufferPoolSize="1048576000" maxReceivedMessageSize="1048576000"
                   messageEncoding="Text" textEncoding="utf-8" 
                   useDefaultWebProxy="true" allowCookies="false">
               <readerQuotas maxDepth="104857600" maxStringContentLength="104857600" 
                             maxArrayLength="104857600" maxBytesPerRead="1048576000" 
                             maxNameTableCharCount="104857600" />
               <reliableSession ordered="true" inactivityTimeout="00:10:00"
                                enabled="false" />
               <security mode="TransportWithMessageCredential">
                   <transport clientCredentialType="Windows" 
                              proxyCredentialType="None" realm="" />
                   <message clientCredentialType="Windows" 
                            negotiateServiceCredential="true" algorithmSuite="Default" 
                            establishSecurityContext="true" />
               </security>
            </binding>
        </wsHttpBinding>
   </bindings>
   <client>
       <endpoint name="WSHttpBinding_IService11"
           address="http://abc.com/API/serv.svc"
           binding="wsHttpBinding" 
           bindingConfiguration="WSHttpBinding_IService11"
           contract="SmartConnectRepublic.IService1" >
           <identity>
               <dns value="localhost" />
           </identity>
       </endpoint>
       <endpoint name="BasicHttpBinding_IService1" 
           address="http://localhost:4649/Service1.svc" 
           binding="basicHttpBinding"
           bindingConfiguration="wcfSmartConnect" 
           contract="SmartConnect.IService1" />
   </client>
</system.serviceModel>
like image 571
Pinu Avatar asked Nov 05 '22 15:11

Pinu


1 Answers

Can you tell us a bit about your setup?

  • what binding do you use?
  • is this the only service method? If not: do the others work?
  • show us the configs on client and server! (everything inside <system.serviceModel> is of interest)

It would appear as if the client times out waiting for the server - this can be because the server takes too long to respond (if you do a lot of data loading); in that case, you need to increase your timeouts on the server and the client

Or you might be sending too large a data packet over the wire - in that case, you might also need to increase the settings for maxReceivedMessageSize et al.

@Pinu: are you trying to upload 5 MB? You have transferMode=StreamRequest, which means your request from the client to the server will be streamed.

If you're transferring 5 MB, it's a good idea to stream - which way do you transfer those bytes??

like image 51
marc_s Avatar answered Nov 15 '22 06:11

marc_s