WCF error 413 Request Entity too la - c#

I have recently a new exception. When I try to call a method with a byte array in parameter I get a 413 error.
I try to change maxBufferSize, maxReceivedMessageSize and maxBufferPoolSize but nothing had changed.
In my app.config of my application I have :
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="1116553600"
maxBufferPoolSize="1116553600"
maxBufferSize="1116553600"/>
</basicHttpBinding>
<wsHttpBinding>
<binding name="mex" maxReceivedMessageSize="1116553600"
maxBufferPoolSize="1116553600">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:9804/ServiceBX.svc/soap"
binding="basicHttpBinding" bindingConfiguration="soap" contract="ServiceReferenceBX.ServiceBX"
name="soap" />
</client>
</system.serviceModel>
And in my web.config of my WCF service I have :
<system.serviceModel>
<services>
<service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
<endpoint name="rest" address="" binding="webHttpBinding" contract="BXSportWCFLib.ServiceBX" behaviorConfiguration="restBehavior" />
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="BXSportWCFLib.ServiceBX" />
<endpoint name="soap" address="soap" binding="basicHttpBinding" contract="BXSportWCFLib.ServiceBX" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
I see lot of things on this error but anything I try don't work.
First I like to know in wich file I must modify ?
I try to add bindings and modify my endoint but now when I execute my application I had a : "The requested service can't be activated"
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="116553600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="web"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="11653600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
<endpoint name="rest"
address=""
binding="webHttpBinding"
bindingConfiguration="web"
contract="BXSportWCFLib.ServiceBX"
behaviorConfiguration="restBehavior" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
bindingConfiguration="soap"
contract="BXSportWCFLib.ServiceBX" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetaDataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Thanks

It sounds like you're receiving the error when calling the service, so you need to fix the config file for the service, not the client.
The posted config for the service does not specify any binding configurations, so WCF will use the default settings for the specified values. You need to a) define the binding configurations you want to use and b) assign them to the endpoints. Failure to do both will result in WCF still using the default values.
In your service config, add the following in the <system.serviceModel> section:
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="116553600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</basicHttpBinding>
<webHttpBinding
<binding name="web"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="11653600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</webHttpBinding>
</bindings>
Note that you need to specify the configuration for both basicHttpBinding and webHttpBinding.
Next, assign them to the correct endpoints via the bindingConfiguration attribute on the <endpoint> element:
<endpoint name="rest"
address=""
binding="webHttpBinding"
bindingConfiguration="web"
contract="BXSportWCFLib.ServiceBX"
behaviorConfiguration="restBehavior" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
bindingConfiguration="soap"
contract="BXSportWCFLib.ServiceBX" />
Thirdly, your mex endpoint is specifying the wrong contract - it should be IMetaDataExchange:
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetaDataExchange" />
If you still get the 413 error, you will also want to adjust the maxRequestLength in <httpRuntime> element. This goes in the config file in the <system.webServer> section:
<system.web>
<httpRuntime maxRequestLength="116533600" />
</system.web>
the default for maxRequestLength is 4 MB, but most likely the issue is with the values being used for the bindings on your service.

The solution work !
I had add bindings but I change the IMetaDataExchange and write BXSportWCFLib.ServiceBX and I have not the message "The requested service can't be activated"
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="116553600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="web"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="11653600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
<endpoint name="rest"
address=""
binding="webHttpBinding"
bindingConfiguration="web"
contract="BXSportWCFLib.ServiceBX"
behaviorConfiguration="restBehavior" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
bindingConfiguration="soap"
contract="BXSportWCFLib.ServiceBX" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetaDataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>

Related

WCF custombinding mutualcertificate keep getting 'The request message must be protected' error

i have a server with wcf soap services. With simple httpbinding configuration everything worked perfectly.
After I changed the web.config to custombinding I keep getting the same error :
The request message must be protected. This is required by an operation of the contract ('IMyServices','http://tempuri.org/'). The protection must be provided by the binding ('BasicHttpBinding','http://tempuri.org/').
This is my web.config :
<system.serviceModel>
<bindings>
<customBinding>
<binding name="MyBinding">
<textMessageEncoding messageVersion="Soap11WSAddressingAugust2004" />
<security authenticationMode="MutualCertificate" requireDerivedKeys="false"
messageProtectionOrder="SignBeforeEncrypt" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
<httpTransport keepAliveEnabled="false" />
</binding>
</customBinding>
</bindings>
<services>
<service behaviorConfiguration="MyBehavior" name="NewWCF.MyServices">
<endpoint address="" binding="customBinding" bindingConfiguration="MyBinding"
name="wsHttpMembershipEndpoint" contract="NewWCF.IMyServices" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://10.130.111.111/NewWCF" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceCredentials>
<clientCertificate>
<certificate findValue="CN=Central-Gateway" x509FindType="FindBySubjectDistinguishedName" storeName="TrustedPeople" />
<authentication revocationMode="NoCheck"
certificateValidationMode = "None"/>
</clientCertificate>
<serviceCertificate findValue="CN=MySrvTst" x509FindType="FindBySubjectDistinguishedName" storeName="My" storeLocation="LocalMachine" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceSecurityAudit serviceAuthorizationAuditLevel="SuccessOrFailure"
messageAuthenticationAuditLevel="SuccessOrFailure" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
lang-xml -->
Both certificates appear correctly in mmc.exe
I try to test it through a browser calling .svc path , should it work that way or does it fail because of the certificates ?
Is there a way to see a more detailed error?
What can be the problem?
Thanks in advance,
Brian.

WCF: Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8733/'

After adding serviceAuthorization to config file, a problem occurred. When adding a service to the project, it does not see the netTcp connection. Without serviceAuthorization everything works fine.
Config:
<system.serviceModel>
<services>
<service behaviorConfiguration="mexBehavior" name="ChartServices.Service.ChartManagerService">
<endpoint address="ChartServices" binding="wsHttpBinding" bindingConfiguration="wsBindingConfig"
name="wsBinding_UserService" contract="ChartServices.Services_Contract.IUserService" />
<endpoint address="ChartServices" binding="netTcpBinding" bindingConfiguration="netTcpBindingConfig"
name="netTcp_UserService" contract="ChartServices.Services_Contract.IUserService" />
<endpoint address="mex" binding="mexTcpBinding" name="mexTcp"
contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpBinding" name="mexHttp"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8733/" />
<add baseAddress="http://localhost:8734/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsBindingConfig">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="netTcpBindingConfig">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" />
</clientCertificate>
<serviceCertificate findValue="RootCATest" storeLocation="LocalMachine"
storeName="My" x509FindType="FindByIssuerName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="ChartServices.CustomUserNameValidator, ChartServices" />
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="ChartServices.MyServiceAuthorizationManager, ChartServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<authorizationPolicies>
<add policyType="ChartServices.AuthorizationPolicy, ChartServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Tried different options but could not solve the problem
Visual Studio 2017 problem!!!!!!!
https://github.com/dotnet/wcf/issues/1741

WCF with windows authentication problems

I am building wcf aplication that will work only with users that have User+Password to the windows where this wcf is located.That mean is my wcf located on server X and i call function GetData(5) i will see the logon form (the same users that in windows) and entered User+Password and then get data back, my main goal is to pass User+Password to avoid this logon window,but now i can't forse my wcf to ask for windows authentication,it is returning data to everyone.
What i am doing wrong?
I am using Vs2012(4.5)
P.s if any one have example of wcf that use windows authentication i
will be very happy to see it.
My webConfig
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<authentication mode="Windows" />
<identity impersonate="false" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfService10.Service1">
<endpoint address="WCF10" binding="basicHttpBinding" bindingConfiguration="NewBinding10"
contract="WcfService10.IService1" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="NewBinding10">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Windows" customUserNamePasswordValidatorType="Type, Assembly" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
To pass alternative windows credentials to a service, use the following code:
var proxy = new MyServiceClient();
proxy.ClientCredentials.Windows.ClientCredential.Domain = "MyDomain";
proxy.ClientCredentials.Windows.ClientCredential.UserName = "MyUsername";
proxy.ClientCredentials.Windows.ClientCredential.Password = "MyPassword";
proxy.DoSomething();
proxy.Close();
Here one config with webHttpBinding and Windows Transport security. You have to change the service name, baseAddress, contract="Server.IServicemame"
<system.serviceModel>
<!--Services-->
<services>
<service name="Server.servicemame">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9011/servicemame/service"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" contract="Server.IServicemame" bindingConfiguration="HttpBindingWithSecurity">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<!--Behaviors-->
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization impersonateCallerForAllOperations="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceCredentials>
<windowsAuthentication allowAnonymousLogons="false"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<!--Bindings-->
<bindings>
<webHttpBinding>
<binding name="HttpBindingWithSecurity">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

WCF Service End Point Not Found

i have deployed my wcf service on IIS.. Its giving me this error when I want to access its one of method "EndPoint Not Found" While locally its working fine for me and returning me data.
Here is my Web.config Bindings Information
<system.webServer>
<directoryBrowse enabled="false" />
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="RTAService" behaviorConfiguration="WtfServiceBehaviour">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="wtfSslBinding" behaviorConfiguration="WebHttpBehaviour" contract="IRTAService" />
<endpoint address="soap" binding="basicHttpBinding" contract="IRTAService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="wtfSslBinding" />
<binding name="streamedBinding"
maxBufferSize="65536"
maxReceivedMessageSize="2000000000"
transferMode="Streamed">
<readerQuotas maxDepth="500000000"
maxArrayLength="500000000" maxBytesPerRead="500000000"
maxNameTableCharCount="500000000" maxStringContentLength="500000000"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebHttpBehaviour">
<webHttp helpEnabled="true" defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json"
automaticFormatSelectionEnabled="false" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WtfServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Please tell me any work around for that.
I dont see endpoint defined any where . Your config should have something like this.`
<endpoint address="http://localhost:57800/Services.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IServices" contract="MYServices.IServices"
name="BasicHttpBinding_IServices" />

Enable WCF calls in a Windows Phone Mango

I developed a WCF in a Managed Windows Service, based on this tutorial
This is how my interface are defined :
namespace HomeAutomationWindowsService
{
[ServiceContract]
public interface IHomeAutomation
{
[OperationContract]
string connect();
[OperationContract]
Boolean sendAction(string address, string command);
}
}
And my App.config file is like this :
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Unsecured">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="HomeAutomationWindowsService.HomeAutomationService"
behaviorConfiguration="HomeAutomationServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://192.168.11.178:8000/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/service -->
<endpoint address=""
contract="HomeAutomationWindowsService.IHomeAutomation"
binding="wsHttpBinding"
bindingConfiguration="Unsecured" />
<!-- the mex endpoint is explosed at http://192.168.11.178:8000/ mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="HomeAutomationServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
When I make a call from a Console or a WPF App I can see the public methods, but when I do it using Windows Phone I can't see anything.
What I should do to make my WCF or Windows Phone communicating together.
I think WsHttpBinding is not supported by WP7. Try using BasicHttpBinding:
Web.config:
<system.serviceModel>
<services>
<service name="MyProject.MyService" behaviorConfiguration="behavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="binding" contract="MyProject.MyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="binding">
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
After adding the webservice to your WP7 project (add service reference) the ServiceReferences.ClientConfig should look like (adding web service with WsHttpBinding generates an empty file):
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:44300/Services/DataService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataService"
contract="DataService.DataService" name="BasicHttpBinding_DataService" />
</client>
</system.serviceModel>
</configuration>

Categories