The remote server returned an error: (400) Bad Request
Posted
by pravakar
on Stack Overflow
See other posts from Stack Overflow
or by pravakar
Published on 2009-11-06T09:35:21Z
Indexed on
2010/04/21
8:03 UTC
Read the original article
Hit count: 314
ASP.NET
Hi,
I am getting the following errors:
"The remote server returned an error: (400) Bad Request"
"Requested time out"
sometimes when connecting to a host using a web service. If the XML returned is 5 kb then it is working fine, but if the size is 450kb or above it is displaying the error.
Below is my code as well as the config file that resides at the client system. We don't have access to the settings of the server.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim fileName As String = Server.MapPath("capitaljobs2.xml")
Dim client = New CapitalJobsService.DataServiceClient("WSHttpBinding_IDataService", "http://xyz/webservice.svc")
Dim userAccount = New UserAccount()
'replace here
Dim jobAdList = client.GetProviderJobs(userAccount)
'## Needed only to create XML files - do not ucomment - will overwrite files
'if (jobAdList != null)
' SerialiseJobAds(fileName, jobAdList);
'## Read new ads from Xml file
Dim capitalJobsList = DeserialiseJobdAds(fileName)
UpdateProviderJobsFromXml(client, userAccount, capitalJobsList)
client.Close()
End Sub
Private Shared Function DeserialiseJobdAds(ByVal fileName As String) As CapitalJobsService.CapitalJobsList
Dim capitalJobsList As CapitalJobsService.CapitalJobsList
' Deserialize the data and read it from the instance
If File.Exists(fileName) Then
Dim fs = New FileStream(fileName, FileMode.Open)
Dim reader = XmlDictionaryReader.CreateTextReader(fs, New XmlDictionaryReaderQuotas())
Dim ser2 = New DataContractSerializer(GetType(CapitalJobsList))
capitalJobsList = DirectCast(ser2.ReadObject(reader, True), CapitalJobsList)
reader.Close()
fs.Close()
Return capitalJobsList
End If
Return Nothing
End Function
And the config file
<system.web>
<httpRuntime maxRequestLength="524288" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDataService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://xyz/DataService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataService" contract="CapitalJobsService.IDataService" name="WSHttpBinding_IDataService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
I am using "Fiddler" to track the activities it is reading and terminating file like
* FIDDLER: RawDisplay truncated at 16384 characters. Right-click to disable truncation. *
But in config the number 16348 is not mentioned anywhere.
Can you figure out if the error is on client or server side? The settings above are on the client side.
Thanks in advance.
© Stack Overflow or respective owner