Configure WCF with the <services> tag

I am trying to solve the WCF error found in my previous question . Essentially the error:

The maximum length of the string length (8192) was exceeded when reading XML data.

And someone suggested using the services tag in my web.config to solve my problem.

Now I have a different problem. I cannot understand how I can configure the services tag in my web.config to work correctly on my server. When I try to use the services tag, I always get the following error:

The server did not give a meaningful response; this can be caused by a contract mismatch, a premature disconnection of the session, or an internal server error.

Here is my web.config with services tag:

<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_Service1" 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="10000" 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:53931/WCF/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service1" contract="ServiceReference.Service1" name="BasicHttpBinding_Service1" /> </client> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <!--PROBLEM SOMEWHERE IN THE SERVICES TAG--> <services> <service behaviorConfiguration="NewBehavior" name="AspPersonalWebsite.ServiceReference"> <endpoint address="http://localhost:53931/WCF/Service1.svc" binding="basicHttpBinding" contract="ServiceReference.Service1" bindingConfiguration="BasicHttpBinding_Service1" /> </service> </services> 

Please note that when you remove the services tag, everything works fine, but then I can not solve my original problem posted on my previous question.

can someone tell me that I'm doing something wrong on my web.config, especially in the service tag ?!

+6
web-config wcf
source share
3 answers

Ok, allow this:

First , you need to define a basicHttpBinding custom binding configuration with some custom settings:

 <bindings> <basicHttpBinding> <binding name="LargeSettings" maxBufferSize="524288" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"> <readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None" /> </binding> </basicHttpBinding> </bindings> 

This section should be both on the web.config server on the server, and on your client-side configuration.

The second time , on the server side , you need to have a <services> tag that defines your service and its endpoints and their configuration:

 <services> <service name="YourNamespace.YourClassName" behaviorConfiguration="ServiceWithMetadata"> <endpoint name="Default" address="http://localhost:53931/WCF/Service1.svc" binding="basicHttpBinding" bindingConfiguration="LargeSettings" contract="YourNamespace.IServiceContract" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServiceWithMetadata"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> 

Points to check:

  • your service name must be the full name ( YourNamespace.YourClassName ) of your service class — the class that implements your service contract
  • your endpoint service contract must also be the fully qualified name of your service contract ( YourNamespace.IYourServiceContract )
  • behavior. The configuration of your <service> must reference and exactly match the name= attribute, as defined in the <behaviors> section

And thirdly , on the client side, you need something like this:

 <client> <endpoint name="Default" address="http://localhost:53931/WCF/Service1.svc" binding="basicHttpBinding" bindingConfiguration="LargeSettings" contract="ServiceReference.IYourService" /> </client> 

You need to specify the endpoint defined in the definition of your service on the server side, you need to use the same binding and binding configuration, and you need to use the service contract as defined in your service link.

+25
source share

For those using the built-in service link, just use .Endpoint.Binding =THE NEW BINDING

Example:

 BasicHttpBinding b = new BasicHttpBinding(); b.Security.Mode = BasicHttpSecurityMode.Transport; ... b.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; MyWebServiceReference.ServiceReferenceSoapClient objRE = new MyWebServiceReference.ServiceReferenceSoapClient("ServiceReferenceSoap", "URI"); objRE.Endpoint.Binding = b; 
+1
source share

Use this parameter for your bindings,

  <basicHttpBinding> <binding maxReceivedMessageSize="2147483647" messageEncoding="Text" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" > <readerQuotas maxStringContentLength="525288"></readerQuotas> </binding> </basicHttpBinding> 
-one
source share

All Articles