WCF SOAP service returns Not Found for a large request and works OK for a smaller one - wcf

I have a SilverLight application that calls WCF service by POST via SSL and sends large request. Everything works OK on a local machine with a self-signed certificate. Moreover, it works on a remote server but only for a small request. When the application make a POST request (using SOAP) for a big scope of data I get a CommunicationException: "The remote server returned an error: NotFound." The same use case on the local machine with absolutely the same web.config file (except of the sql connection string) works without the issue. It seems that the problem in the IIS configuration. I tried to investigate IIS logs but did not find any information about the requests as something before the logging kernel rejected the request. I have read a lot of articles where people propose different settings of the endpoints bindings, tried them but have not achieved success.
My configuration of the services is the next:
<system.web>
<httpRuntime maxRequestLength="2097151"/>
<!--...(other settings) -->
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<services>
<!--... (other services)-->
<service name="SD.Web.Services.ClientUser.UserLayersService">
<endpoint address="soap"
binding="basicHttpBinding"
contract="SD.Web.Services.ClientUser.IUserLayersService" />
<endpoint address="json"
behaviorConfiguration="SD.Web.Services.AspNetAjaxBehavior"
binding="webHttpBinding"
contract="SD.Web.Services.ClientUser.IUserLayersService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<security mode="Transport" />
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SD.Web.Services.AspNetAjaxBehavior">
<webHttp defaultBodyStyle="Bare"
defaultOutgoingResponseFormat="Json"
automaticFormatSelectionEnabled="false"
faultExceptionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

I found the answer using Fiddler 4. Reader quotas have to be set.
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Transport" />
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>

Related

WCF Error 400 Bad Request when sending message bigger than 100mb

I made my first WCF service where I'm receiving data I have to process. The problem occurs when I send larger amounts, a 100mb soap message, of data at once, I get the reply Error 400 Bad Request.
I tried setting maxReceivedMessageSize, maxBufferSize, maxAllowedContentLength, readerQuotas that are referenced in other questions, but nothing seems to work or just makes the service not work at all.
These are the current settings in my web.config
<services>
<service name="RMQServices.RMQ_WS1" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="webHttp" contract="RMQServices.RMQService" binding="basicHttpBinding" bindingConfiguration="myBasic" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="myBasic" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
Am I still missing something in the config for it to work and accept larger requests?
EDIT:
If I send data via a service reference then it accepts even 1GB soap messages. But if I try to send it via HttpWebRequest with a prebuilt SOAP XML, then it still returns a Bad Request. So the problem seems to be in how I send the data.
make sure your client config also have these values
<client>
<endpoint address="[address]" binding="basicHttpBinding" bindingConfiguration="myBasic" contract="" name="Name" />
</client>
And then add
<bindings>
<basicHttpBinding>
<binding name="myBasic" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
if this does not work, remove the security from the binding and then validate
Please try to add the following code snippets.
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<httpRuntime maxRequestLength="2147483647" executionTimeout="3600" />
</system.web>
</configuration>
Also, Don’t forget to apply the configuration between the client-side and server-side (you should also add this configuration on both the client-side and server-side endpoints).
Feel free to let me know if the problem still exists.

WCF Streaming not able to transfer large files

I am making a WCF Service for transfering files. I have only basic WCF understanding and followed the MSDN tutorial: WCF Tutorial
I started using byte arrays for transfering the files but as soon as the files got a little big (100kb was enough) it would fail with bad request.
I followed another guide and changed to streaming with messages, and it works with small files as well but fails with bigger ones like the old version. I suspect the fault lies in my config file as the one generated by svcutil.exe doesn't say anything about streaming.
This is my clients app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDocPublisher" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="200000000" maxStringContentLength="200000000" maxArrayLength="200000000"
maxBytesPerRead="200000000" maxNameTableCharCount="200000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService/docPublisher"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDocPublisher"
contract="IDocPublisher" name="WSHttpBinding_IDocPublisher">
<identity>
<userPrincipalName value="Emil-PC\Emil" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
And this is the servers app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"
httpHelpPageEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="serviceBehavior"
name="DocPublisher">
<endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService"
name="basicHttpStream"
binding="basicHttpBinding"
bindingConfiguration="httpLargeMessageStream"
contract="IDocPublisher" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="httpLargeMessageStream"
maxReceivedMessageSize="200000000"
maxBufferSize="200000000"
transferMode="Streamed"
messageEncoding="Mtom" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
Try to increase send timeout and reader quotas on client side, set buffer size on server side.
Turns out the config files weren't the real problem, the problem was that the servers app.config was never used as the msdn tutorial doesn't use app.config but creates the endpoints in the main method.

silverlight wcf service prompt for credentials

I have a silverlight app that calls a wcf service, and I'm having trouble deploying it.
I can publish the files, but when the app tries to access the service, it doesnt seem to get anything back.
The app is set for client credentials with Windows Authentication
What's weird is that its not throwing errors. The silverlight app just seems to stop with a blank screen.
To test the deployed service, I try to access it from a browser, and I'm prompted for credentials. I try putting in my name and password, but it just asks me for credentials again.
What credentials is it prompting me for?
How can I get past this?
Here's the client config:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="../Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
Here's the web config:
<configuration>
<system.web>
<httpRuntime executionTimeout="180" />
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpStreamingBinding" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed" receiveTimeout="01:00:00" sendTimeout="01:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
<!--<transport clientCredentialType="Ntlm" />-->
</security>
</binding>
</basicHttpBinding>
</bindings>
<client />
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
multipleSiteBindingsEnabled="true" />
<services>
<service name="CitationAir.MissionPlanning.WebService.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpStreamingBinding"
contract="CitationAir.MissionPlanning.WebService.IService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Using Windows Authentication, you will get a password prompt if Integrated Windows Authentication is turned off`, which can be because you are using a browser other than Internet Explorer.
The password wont work if your account is locked out, if you are connecting to a service in an untrusted domain, or if your account does not have sufficient permissions to access the resource.
Could it be any of those in this case?

WCF IIS-hosted wsHttpBinding service - svcutil generates proxy with basicHttpBinding!

I consider myself pretty expert at WCF but this has me stumped. I don't know if this is a .NET Framework 4/WCF 4 thing with it's automatic configuration or what but I am getting strange behavior. I basically have a WCF 4 WCF service hosted in IIS project. It all worked and then I went in and switched the config from basicHttpBinding to wsHttpBinding. I tried to Update the Service Reference in my consuming app and I get basicHttpBinding output in the generated config. So, of course, I dropped down and ran svcutil.exe aggainst the .svc file and same results. This is the config file (Blah substituted for name that I can't use in public):
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows"></authentication>
<identity impersonate="true"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpEndpointBinding">
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Blah.Services.RONScheduler.BlahService.BlahDataServiceBehavior"
name="Blah.Services.RONScheduler.FAMService">
<endpoint address="BlahDataService" binding="wsHttpBinding" bindingConfiguration="WSHttpEndpointBinding"
name="WSHttpEndpoint" contract="Blah.Services.RONScheduler.FAMService.IBlahDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Blah.Services.RONScheduler.BlahService.BlahDataServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
This is what I get generated out before I clean out the unncessary stuff:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IBlahDataService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/BlahService/BlahDataService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBlahDataService"
contract="IBlahDataService" name="BasicHttpBinding_IBlahDataService" />
</client>
</system.serviceModel>
As you can see it's as if it's ignoring the wsHttpBinding setting in the config. What gives?
Have you checked your default protocol bindings, a new feature in WCF 4 ??
By default, they're in your machine.config, and should look like this:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="" />
<add scheme="net.tcp" binding="netTcpBinding" bindingConfiguration=""/>
<add scheme="net.pipe" binding="netNamedPipeBinding" bindingConfiguration=""/>
<add scheme="net.msmq" binding="netMsmqBinding" bindingConfiguration=""/>
</protocolMapping>
So this kinda implies to me that if you're hitting a HTTP address, WCF 4 will use basicHttpBinding by default.
You can change those bindings in your own configs, if needed.
Found this in A Developer's Introduction to Windows Communication Foundation 4
Given the configurations you provided, my guess would be that the service name is invalid and the host falls back to default configuration.
Make sure the service name matches the implementation class name.
I came to this conclusion because the interface name is Blah.Services.RONScheduler.FAMService.IBlahDataService and the class name is Blah.Services.RONScheduler.FAMService. It looks like there is something missing after FAMService.

WCF Service Communication Exception Due to Parameter Size

I've got a WCF Web MEthod that takes in an XElement object as a parameter. For one of my XML files (sized at 600KB or so) this works just fine, however, for this bigger XML file (about 5MB) I get a CommunicationException right away.
I've already increased the message sizes for my binding. Below is the ServiceModel section of my web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="BIMIntegrationWS.metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BIMIntegrationWS.IntegrationService.customBinding0"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="BIMIntegrationWS.BIMIntegrationWS" behaviorConfiguration="BIMIntegrationWS.metadataBehavior">
<endpoint address="" binding="customBinding" bindingConfiguration="BIMIntegrationWS.IntegrationService.customBinding0"
contract="BIMIntegrationWS.IBIMIntegrationService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
On the client, my ClientConfig looks like this:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IBIMIntegrationService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:1895/IntegrationService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IBIMIntegrationService"
contract="BIMIntegrationService.IBIMIntegrationService" name="customBindingEndpoint" />
</client>
</system.serviceModel>
Thanks in advance!
try to add following snippet into your web.config for the service application:
<system.web>
<httpRuntime maxRequestLength="16384" /> <!-- 16MB -->
</system.web>
When you host the service in web server you also have to tweak allowed request size for the web server.
Best regards,
Ladislav
Maybe your XElement has too many nodes/child elements, and you need to set the maxItemsInObjectGraph attribute under dataContractSerializer to something larger?
You probably need to change the values of the attributes of the <readerQuotas /> sub element of <binaryMessageEncoding />.
For more information, see:
http://msdn.microsoft.com/en-us/library/ms731325.aspx
http://forums.silverlight.net/forums/p/88704/205040.aspx
Update:
Can you try to increase the maxAllowedContentLength as described here:
http://social.msdn.microsoft.com/Forums/en/wcf/thread/e6e21132-ad3f-4135-8ab9-77923b099907
Do you know how to turn off VS host and to just deploy to IIS and give it a ping. Normal IIS 7 on your dev box will do just fine. You can still attach debugger etc, just won't have instantaneous F5 gratification but since your ocode is not dying on startup you don't need to see if from the fist line anyway :-)
If you would need to attach very early you could could make a mimimal method that doesn't tounch anything at all and just returns int constnat - just to bring up app pool so you can attach.