Recently I have been struggling with a WCF service that should receive image data as a byte[]… supposedly it should be peanuts but I had a hard time achieving it.
Fortunately I belong to a Portuguese .Net community (www.netponto.pt) where with their help and a lot of forums and blog reading I finally nailed it. I should reference some of them but I didn’t wrote them down at the time so my apologies to sources that also helped me out.
One of the things to have in mind is the binding as it should state that you are able to receive large amount of data. I will not detail many things but you should know that being able to receive data also means that you are also an easy duck if someone wants to target you. Be careful when doing so. also there are 3 types of bindings at least that you should know: basicHttpBinding, wsHttpBinding (soap ones) and webHttpBinding (rest).
my binding example:
<basicHttpBinding >
<binding name="LargeWeb"
maxBufferPoolSize="1500000"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">
<readerQuotas
maxArrayLength="2147483647"
maxBytesPerRead="656000"
maxDepth="32"
maxNameTableCharCount="656000"
maxStringContentLength="2147483647"
/>
</binding>
</basicHttpBinding >
After that you should define config for your service. I have read that baseAddress was ignored by IIS but it happened not to be so when you want to host many addresses on same url. While defining your service you also have to set endpoint configuration:
<services>
<service name="Me.Services.Service" behaviorConfiguration="CustomBehaviour.LargeWeb">
<host>
<baseAddresses>
<add baseAddress="http://localhost/Me.Services/Services" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeWeb" contract="Me.Services.IService" >
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</endpoint>
</service>
</services>
As you can see I have set a behavior for “Service”. However I have more services running on this url. That’s why I have a unnamed behavior on my services Behavior section:
<behaviors>
<serviceBehaviors>
<behavior name="CustomBehaviour.LargeWeb">
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior >
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
These are the main items to do the trick on the surface. Have in mind that there changing standard behavior of things affect how they perform for better if well done but also for bad.
If you are like me that go nuts when every people talks on small things but no one shows the whole cake, then you can see web.config all set for this need:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding >
<binding name="LargeWeb"
maxBufferPoolSize="1500000"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647">
<readerQuotas
maxArrayLength="2147483647"
maxBytesPerRead="656000"
maxDepth="32"
maxNameTableCharCount="656000"
maxStringContentLength="2147483647"
/>
</binding>
</basicHttpBinding >
</bindings>
<services>
<service name="Me.Services.Service" behaviorConfiguration="CustomBehaviour.LargeWeb">
<host>
<baseAddresses>
<add baseAddress="http://localhost/Me.Services/Services" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeWeb" contract="Me.Services.IService" >
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CustomBehaviour.LargeWeb">
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior >
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Hope to help.






