I have an ASP.NET 4.0 Application.
A webservice is hosted using a .svc
file linking a source (service implementation).
The web service .svc
file is located inside a directory WebServs
in the application root directory: MyApp/WebServs/mysvc.svc
.
The web service is set using the Web.config
(in the root directory).
<!-- Service model -->
<system.serviceModel>
<services>
<service name="DataAccessService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_ISRV"
contract="MyNamespace.ISRV">
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_ISRV" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="1310720"
maxArrayLength="16384"
maxBytesPerRead="24096"
maxDepth="10000"
maxNameTableCharCount="16384"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
OK!
When I call the web service, I create the channel using a routine in order to encapsulate this commonly used logic:
public static ISRV GetService() {
try {
// Create the service endpoint
BasicHttpBinding bhttpb = new BasicHttpBinding(
BasicHttpSecurityMode.TransportCredentialOnly);
bhttpb.MaxReceivedMessageSize = 2147483647;
bhttpb.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
bhttpb.ReaderQuotas.MaxArrayLength = 16384);
bhttpb.ReaderQuotas.MaxBytesPerRead = 24096);
bhttpb.ReaderQuotas.MaxDepth = 10000);
bhttpb.ReaderQuotas.MaxNameTableCharCount = 16384);
bhttpb.ReaderQuotas.MaxStringContentLength = 1310720);
ServiceEndpoint httpEndpoint =
new ServiceEndpoint(
ContractDescription.GetContract(typeof(ISRV)),
bhttpb,
new EndpointAddress());
// Create channel factory and get proper channel for service.
ChannelFactory<ISRV> channelFactory = new ChannelFactory<ISRV>(httpEndpoint);
IDAS svc = channelFactory.CreateChannel();
return svc;
} catch (Exception e) {
throw new DASException("DAS Exception: " + e.Message);
}
}
This routine is called by clients. Whilke the Web.config
is used to configure the service server side.
When I try to execute my service with large messages (with tiny messages all's right) I get:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://((Namespace)):((Operation)). The InnerException message was 'There was an error deserializing the object of type ((Type)), App_Code.s5qoir2n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 31, position 1309.'. Please see InnerException for more details.
Don't understand. Both service and client have common settings, and this reads defaut values????? Furthermore I did as many other users did following instructions here in StackOverflow.
Please help me. Thankyou
You specified WCF 4.0 (well, ASP.NET 4.0 to be exact), so I wonder if the problem you're encountering is that you're actually hitting a default endpoint, which would use the default values for the binding unless otherwise overridden?
WCF 4.0 will supply a default endpoint (set to where the service is located at). That default endpoint will most likely use the default values for the binding (8192 in the case of the MaxStringContentLength).
Since you do all the configuration for the service in the directory above the WebServs directory (the root), perhaps it's resorting to a default endpoint? I do realize that the Web.config files will inherit from the ones above, but this is something to at least consider, if you haven't already.
More info on default endpoints and other changes for 4.0 can be found here: A Developer's Introduction to Windows Communication Foundation 4