I have been trying to search for this error but no luck so far.
So I have a service on my client with this web.config
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.mywebsite.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="ServiceBehavior" name="UploadService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="IUploadService">
<identity>
<dns value="http://www.mywebsites.com/" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" maxReceivedMessageSize="4194304">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
and on the client I have this configuration
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IUploadService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:30:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://www.mywebsite.com/UploadService.svc"
binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService"
name="WSHttpBinding_IUploadService">
<identity>
<dns value="http://www.mywebsite.com/" />
</identity>
</endpoint>
</client>
and I am uploading the files like this :-
using (Stream stream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read))
{
try
{
using (UploadServiceClient upc = new UploadServiceClient())
{
upc.UploadFile(stream);
}
}
catch (Exception exc)
{
}
}
for small files it works fine, but for large XML files, this failes with 400 Bad Request. What I can do to change these settings to get large XML file to transfer?
Thanks for your help and time
UPDATED Client app.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_IUploadService" receiveTimeout="00:20:00"
bypassProxyOnLocal="true" maxBufferSize="4194304" maxReceivedMessageSize="4194304"
messageEncoding="Mtom" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.mywebsite.com/UploadService.svc"
binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService"
name="basicHttpBinding_IUploadService">
<identity>
<dns value="http://www.mywebsite.com/" />
</identity>
</endpoint>
</client>
You should to see if the service has the same maxReceivedMessageSize="4194304" as the client and if the XML is indeed smaller than the 4,194,304 byte limit that is set. WCF defaults to a maxReceivedMessageSize of 64K.
UPDATE:
I noticed your config shows the client being configured for basicHttpBinding but the config only shows a wsHttpBinding. The wsHttpBinding config would be ignored by WCF since it doesn't pertain to basicHttpBinding. If the client config file doesn't have a basicHttpBinding element then in .NET 4 a default one is being used. If this is true then you'll run into the 64K limit described above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With