WCF REST Service Template 4.0 "Bad Request" - wcf

I am trying to send a large json string to a WCF Service created with the WCF REST Service Template. If the string is longer 8000 characters I get a "HTTP/1.1 400 Bad Request" error. I have tried added this to my web config:
<bindings>
<webHttpBinding>
<binding name="httpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>
</webHttpBinding>
</bindings>
Any ideas?

You must also setup readerQuotas if you want to pass large strings:
<bindings>
<webHttpBinding>
<binding name="httpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="50000" />
</binding>
</webHttpBinding>
</bindings>

Related

the provided uri scheme https is invalid; expected 'http' in app.config

I have a wcf with like below url
https://localhost:44370/service.svc
I have a window service which is using the above wcf
and in my app.config I configured the same like below
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpsBinding_IService" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:44370/service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpsBinding_IService" contract="FileServer.IService"
name="BasicHttpsBinding_IService" />
</client>
</system.serviceModel>
but I am getting the following error the provided uri scheme https is invalid; expected 'http'
when I changed my binding type into https like below
<system.serviceModel>
<bindings>
<basicHttpsBinding>
<binding name="BasicHttpsBinding_IService" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="https://localhost:44370/service.svc" binding="basicHttpsBinding"
bindingConfiguration="BasicHttpsBinding_IService" contract="FileServer.IService"
name="BasicHttpsBinding_IService" />
</client>
</system.serviceModel>
then I am getting the below error
configuration binding extension 'system.servicemodel/binding.basichttpsbinding' could not be found. verify that this binding extension is properly registered in 'system.servicemodel/binding.basichttpsbinding' and that it is spelled correctly.
what can I do to solve this?
You are trying to use a HTTPS address with a HTTP binding, change the binding type to 'basicHttpsBinding'.
but I am getting the following error the provided uri scheme https is
invalid; expected 'http'
You try adding security mode to the binding, this change will allow you to use https instead of http.
<basicHttpBinding>
<binding name="BasicHttpsBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Transport">
</security>
</binding>
</basicHttpBinding>

Message size quota exceeded on WCF netTcpBinding in remote machine

Always getting exception "The maximum message size quota for incoming messages has been exceeded for the remote channel. See the server logs for more details", in .net c# wcf windows application development.
Up to approximate 72kb size data in DataTable I am able to send remote machine hosting WCF in windows service successfully. But above that throwing exception "The maximum message size quota for incoming messages has been exceeded for the remote channel. See the server logs for more details".
Already did setup of data size management both end.
Client-end App.config:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IProjectService"
maxBufferSize="2147483647" maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647"/>
</binding>
</netTcpBinding>
</bindings>
Remote server-end App.config:
<netTcpBinding>
<binding name="NetTcpBinding_IProjectService" maxBufferSize="2097152"
maxBufferPoolSize="2097152"maxReceivedMessageSize="2097152">
<readerQuotas maxStringContentLength="2097152" />
</binding>
</netTcpBinding>
Also tried same sizes i.e."2147483647" both-end but with same exception always.
Please consider the below configuration.
<bindings>
<netHttpBinding>
<binding name="mybinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
</binding>
</netHttpBinding>
</bindings>
Moreover, please apply the configuration in the service endpoint by using BindingConfiguration name.
<services>
<service name="sv">
<endpoint bindingConfiguration="mybinding" address="" binding="netTcpBinding" contract="isv" ></endpoint>
</service>
</services>
Please apply the configuration on both the serve-end and the client-end.
Feel free to let me know if the problem still exists.

WCF Request Entity Too Large

Try to save image through my WCF service. I noticed that with small file size 3619 it works fine but with big file size 52857 , it doesn't.
Here is my config file
<bindings>
<basicHttpBinding>
<binding name="MaxbasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
If you give a binding a name, it has to be explicitly set on your service with the bindingConfiguration property. Using bindingConfiguration="MaxbasicHttpBinding"on your service configuration (see below) should work. If you do not have a service configuration, then removing name="MaxbasicHttpBinding" from your definition will make it apply to all endpoints.
<services>
<service name="Your.ServiceName">
<endpoint name="Your.ServiceName.EndpointName"
binding="basicHttpBinding"
bindingConfiguration="MaxbasicHttpBinding"
contract="Your.Service.Contract" />
</service>
</services>

WCF returns 404 for large request, maxReceivedMessageSize="2147483647"

Our WCF service on large request returns following error:
"System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://xxx.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
For small requests everything works fine and I am getting correct response from WCF service, the issue is only with large requests.
Settings on the client are as follow:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" openTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:33333/TestService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService" contract="TestService.ITestService" name="BasicHttpBinding_ITestService" />
</client>
</system.serviceModel>
The settings of the WCF service:
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483646" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
What can be the issue?
In this case, the error was not with WCF but with the IIS settings.
The Message was to large for IIS, I have added "maxAllowedContentLength" to the web.config on the server.
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2200000000"/>
</requestFiltering>
</security>
The error message was misleading.
In my case, it was not working even after trying all solutions and setting all limits to max. In last I found out that a Microsoft IIS filtering module Url Scan 3.1 was installed on IIS/website, which have it's own limit to reject incoming requests based on content size and return "404 Not found page".
It's limit can be updated in %windir%\System32\inetsrv\urlscan\UrlScan.ini file by setting MaxAllowedContentLength to the required value.
For eg. following will allow upto 300 mb requests
MaxAllowedContentLength=314572800

Security Exception calling Reporting Services from a Windows Service

I am trying to call the web service for SQL Server Reporting Services from a Windows Service. I can successfully make the call from an Asp.Net MVC website, but when I try to use exactly the same code from a Windows service (with seemingly the same WCF configuration), I get the following error...
Inner Exception: System.ServiceModel.Security.MessageSecurityException
- The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.
Inner Exception: System.Net.WebException - The remote server returned
an error: (401) Unauthorized.
BOTH the application pool for my Asp.Net MVC site AND the Windows Service are set up to use the "Network Service" user.
Here is my WCF configuration in the config file...
<system.serviceModel>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="ReportExecutionServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm=""/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myserver/ReportServer_MSSQL2008/ReportExecution2005.asmx"
binding="basicHttpBinding" bindingConfiguration="ReportExecutionServiceSoap"
contract="ReportService.ReportExecutionServiceSoap" name="ReportExecutionServiceSoap" behaviorConfiguration="ImpersonationBehaviour" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehaviour">
<clientCredentials>
<windows allowedImpersonationLevel="None" allowNtlm="true"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
I have tried all the different "allowedImpersonationLevel" and have tried it without this behaviour defined at all.
Make you have referenced all codes need to run the windows app at som point.