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

Question
-
Hello,
I created a web service which get an image in bytes and save it on the server’s machine.
I get an error when image size is large. When I send images, 23 KB image send successfully but same web service I used it for 155 Kb then it gave me below error.
Error : “The remote server returned an error: (400) Bad Request”
Please help me out.
Friday, June 8, 2012 7:28 AM
Answers
-
Hello Mike,
the error i was getting because of web.config file where i was missing namespace in the service name which is required. see the below web.config file .
<bindings>
<basicHttpBinding>
<binding name="DeviceManagement.Service1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DeviceManagement.Service1Behavior" name="DeviceManagement.Service1">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="DeviceManagement.Service1" contract="DeviceManagement.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DeviceManagement.Service1Behavior">
<!-- 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="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<serviceThrottling maxConcurrentCalls="500"
maxConcurrentSessions="500"
maxConcurrentInstances="500"
/>
</behavior>
</serviceBehaviors>
</behaviors>Hope it will help others to solve this error.
Thanks!!
- Edited by Sonal M Jain Tuesday, June 19, 2012 6:47 AM
- Marked as answer by Mike Feng Tuesday, June 19, 2012 8:53 AM
Tuesday, June 19, 2012 6:46 AM
All replies
-
Hi Sonal,
Welcome to the MSDN Forum.
The service layer also need to configure bindingConfiguration property:
1. Modify the web.config of the service layer:
<services> <service name="DocCube.BusinessLogic.DocumentManager" behaviorConfiguration="HttpGetBehavior"> <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttp" contract="DocCube.Interfaces.IDocumentManager" address=""/> </service> </services>
And then, add new configuration bindingConfiguration:
<bindings> <wsHttpBinding> <binding name="wsHttp" maxReceivedMessageSize ="9999999" messageEncoding="Mtom" maxBufferPoolSize="9999999" > <readerQuotas maxDepth="9999999" maxArrayLength="9999999" maxBytesPerRead="9999999" maxNameTableCharCount="9999999" maxStringContentLength="9999999"/> <security mode="None" /> </binding> </wsHttpBinding> </bindings>
The last step: remove the corresponding config file in client sides to get the updated one.
I hope this will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by RohitArora Monday, June 11, 2012 8:18 AM
- Marked as answer by Mike Feng Tuesday, June 19, 2012 8:54 AM
- Unmarked as answer by Mike Feng Tuesday, June 19, 2012 8:56 AM
Monday, June 11, 2012 8:13 AM -
Hi Mike,
Thank you so much for reply.
As per your suggestion, i made changes in web config as follows:
<services>
<service name="Service1" behaviorConfiguration="Service1Behavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" name="wsHttpEndpoint" contract="IService1" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service></services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding" maxBufferPoolSize="9999999" maxReceivedMessageSize="9999999" messageEncoding="Mtom" textEncoding="utf-8">
<readerQuotas maxDepth="9999999" maxStringContentLength="9999999" maxArrayLength="9999999" maxBytesPerRead="9999999" maxNameTableCharCount="9999999" />
<security mode="None"/> </binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Service1Behavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>but when i add service reference then it gives me an below error:
"The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://localhost:50672/Service1.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:50672/Service1.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Unsupported Media Type.
If the service is defined in the current solution, try building the solution and adding the service reference again."Please help me out.
Monday, June 11, 2012 9:12 AM -
Hi Sonal,
How about change
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" name="wsHttpEndpoint" contract="IService1" />
to
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="IService1" />
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, June 11, 2012 9:20 AM -
No it didnt work.
Its giving same error as above.
Monday, June 11, 2012 9:43 AM -
Hi Mike,
this error has been solved but after updating web config as per your suggestion, its giving me same error.
the remote server returned an error:(400 Bad Request).
Can anyone pleasehelp me out to get it done.
Thank in advance.
Monday, June 11, 2012 2:34 PM -
Hi Sonal,
How about using this way to check what details exceptions occur: http://msdn.microsoft.com/en-us/library/ms733025.aspx?
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, June 12, 2012 3:22 AM -
Hi Sonal,
Do you have any update?
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, June 18, 2012 1:46 PM -
Hello Mike,
the error i was getting because of web.config file where i was missing namespace in the service name which is required. see the below web.config file .
<bindings>
<basicHttpBinding>
<binding name="DeviceManagement.Service1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DeviceManagement.Service1Behavior" name="DeviceManagement.Service1">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="DeviceManagement.Service1" contract="DeviceManagement.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DeviceManagement.Service1Behavior">
<!-- 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="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<serviceThrottling maxConcurrentCalls="500"
maxConcurrentSessions="500"
maxConcurrentInstances="500"
/>
</behavior>
</serviceBehaviors>
</behaviors>Hope it will help others to solve this error.
Thanks!!
- Edited by Sonal M Jain Tuesday, June 19, 2012 6:47 AM
- Marked as answer by Mike Feng Tuesday, June 19, 2012 8:53 AM
Tuesday, June 19, 2012 6:46 AM -
Hi Sonal,
Thank you for sharing your solution here.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, June 19, 2012 8:55 AM