Ok, here it the correct version ;-)

public class AdjustQuotasBehavior : AbstractServiceHostAware
        {
                private const int FIVE_MEGABYTES = 1024 * 1024 * 5;
                protected override void  Opening(ServiceHost serviceHost)
                {
                        var defaultServiceHost = serviceHost as 
DefaultServiceHost;

                        if (defaultServiceHost != null)
                        {
                                defaultServiceHost.EndpointCreated += (_, 
newEndpoint) =>
                                {
                                        var binding = 
newEndpoint.Endpoint.Binding as BasicHttpBinding;
                                        if (binding != null)
                                        {
                                                binding.MaxBufferSize = 
FIVE_MEGABYTES;
                                                binding.MaxBufferPoolSize = 
FIVE_MEGABYTES;
                                                binding.MaxReceivedMessageSize 
= FIVE_MEGABYTES;
                                                
binding.ReaderQuotas.MaxArrayLength = FIVE_MEGABYTES;
                                                binding.ReaderQuotas.MaxDepth = 
FIVE_MEGABYTES;
                                                
binding.ReaderQuotas.MaxStringContentLength = FIVE_MEGABYTES;
                                                
binding.ReaderQuotas.MaxBytesPerRead = FIVE_MEGABYTES;
                                                
binding.ReaderQuotas.MaxNameTableCharCount = FIVE_MEGABYTES;
                                        }
                                };
                        }
                }
        }

Idea was correct, but the Opening hook was called before WCF Faciity added new 
endpoint (hence no endpoints).
Therefore, I just hooked onto the EndpointCreatedEvent

cheers,
  craig

On Oct 14, 2010, at 11:24 AM, João Bragança wrote:

> Unfortunately no. I tried this approach already. As I understand it,
> the only thing allowed in the message body is a Stream, and the method
> must return void. I need to upload an image, insert a record into the
> database, and receive a PK back. This is used in the next request.
> 
> If I switched to net 4.0 would I be able to easily get this done?
> 
> On Oct 14, 5:27 am, Craig Neuwirt <[email protected]> wrote:
>> We may be going about this the wrong way.  I think a better approach for 
>> uploading images is to use the WCF streaming model.  This should eliminate 
>> the size issue, but you will need to configure a binding to specify it.
>> 
>> Here is a good 
>> posthttp://weblogs.asp.net/cibrax/archive/2007/08/29/sending-attachments-...
>> 
>> Are you able to do this in your app?  
>> 
>> On Oct 13, 2010, at 1:26 PM, João Bragança wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> No, not really. The actual client is a Flex/AIR application.
>> 
>>> On Oct 13, 10:22 am, Craig Neuwirt <[email protected]> wrote:
>>>> Do you happen to have  a client the performs the upload with the image 
>>>> culprit?  If not, I can write one.
>> 
>>>> On Oct 12, 2010, at 1:28 PM, João Bragança wrote:
>> 
>>>>> Here's a repo of the bug. Thanks again for taking a look!
>> 
>>>>> ---------- Forwarded message ----------
>>>>> From: Craig Neuwirt <[email protected]>
>>>>> Date: Oct 12, 11:00 am
>>>>> Subject: Wcf Facility, DefaultBinding and Quota Exceeded
>>>>> To: Castle Project Users
>> 
>>>>> Any chance you can zip me a subset of your app so I can run it locally
>>>>> and try and find a solution for you? Just enough to demonstrate the i
>> 
>>>>> On Oct 12, 2010, at 11:24 AM, João Bragança wrote:
>> 
>>>>>> Craig,
>> 
>>>>>> In OnOpening the serviceHost doesn't have any bindings. I tried it in
>>>>>> OnOpened but I got the same error.
>> 
>>>>>> On Oct 12, 8:06 am, Craig Neuwirt <[email protected]> wrote:
>>>>>>> Good question.  WCF makes it a real pain to manipulate the quota stuff.
>> 
>>>>>>> I am not sure the best way to handle this, but this might work for you
>> 
>>>>>>> create
>> 
>>>>>>> public class AdjustQuotasBehavior : AbstractServiceHostAware
>>>>>>> {
>>>>>>>     protected override Opening(ServiceHost serviceHost)
>>>>>>>     {
>>>>>>>         foreach (var endpoint in serviceHost.Description.Endpoints)
>>>>>>>         {
>>>>>>>             var binding = endpoint.Binding as BasicHttpBinding;
>>>>>>>             if (binding != null)
>>>>>>>             {
>>>>>>>                    binding.ReaderQuotas.MaxArrayLength = FIVE_MEGABYTES;
>>>>>>>                   // Do same for other
>>>>>>>             }
>>>>>>>         }
>>>>>>>     }
>> 
>>>>>>> }
>> 
>>>>>>> And register this component in container
>> 
>>>>>>> container.Register(Component.For< AdjustQuotasBehavior>())
>> 
>>>>>>> I have never tried this though.  I could add service binding inference 
>>>>>>> from base address like I did with clients, but this would only work for 
>>>>>>> 3.5
>>>>>>> since I used the default endpoint support out of the box for WCF 4.0
>> 
>>>>>>> Let me know how this goes and we'll find another way if this doesn't 
>>>>>>> work
>> 
>>>>>>> good luck,
>>>>>>>   craig
>> 
>>>>>>> On Oct 12, 2010, at 9:38 AM, João Bragança wrote:
>> 
>>>>>>>> What is the simplest way to override this? I really don't want to
>>>>>>>> configure all the endpoints by hand if I can avoid it.
>> 
>>>>>>>> On Oct 12, 6:34 am, Craig Neuwirt <[email protected]> wrote:
>>>>>>>>> If I recall, the DefaultBinding stuff comes into play when you 
>>>>>>>>> specify endpoints without bindings.  I think in your case, the 
>>>>>>>>> default endpoint logic is getting applied which is based on the base 
>>>>>>>>> address and not the default binding.
>> 
>>>>>>>>> On Oct 11, 2010, at 7:23 PM, João Bragança wrote:
>> 
>>>>>>>>>> I have a WCF service where I need to upload images. I am configuring
>>>>>>>>>> it like so:
>> 
>>>>>>>>>>    public class WcfServicesInstaller : IWindsorInstaller
>>>>>>>>>>    {
>>>>>>>>>>            private const int FIVE_MEGABYTES = 1024*1024*5;
>> 
>>>>>>>>>>            private const string SERVICE_SUFFIX = "Service";
>> 
>>>>>>>>>>            #region IWindsorInstaller Members
>> 
>>>>>>>>>>            public void Install(IWindsorContainer container, 
>>>>>>>>>> IConfigurationStore
>>>>>>>>>> store)
>>>>>>>>>>            {
>>>>>>>>>>                    container.AddFacility<WcfFacility>(f => 
>>>>>>>>>> f.DefaultBinding = new
>>>>>>>>>> BasicHttpBinding
>>>>>>>>>>                                                                      
>>>>>>>>>>               {
>> 
>>>>>>>>>> MaxReceivedMessageSize = FIVE_MEGABYTES,
>>>>>>>>>>                                                                      
>>>>>>>>>>                       // 5
>>>>>>>>>> megs,
>> 
>>>>>>>>>> MaxBufferPoolSize = FIVE_MEGABYTES,
>> 
>>>>>>>>>> MaxBufferSize = FIVE_MEGABYTES,
>> 
>>>>>>>>>> ReaderQuotas = new XmlDictionaryReaderQuotas
>> 
>>>>>>>>>>                            {
>> 
>>>>>>>>>>                                    MaxArrayLength = FIVE_MEGABYTES,
>> 
>>>>>>>>>>                                    MaxDepth = FIVE_MEGABYTES,
>> 
>>>>>>>>>>                                    MaxStringContentLength = 
>>>>>>>>>> FIVE_MEGABYTES,
>> 
>>>>>>>>>>                                    MaxNameTableCharCount = 
>>>>>>>>>> FIVE_MEGABYTES,
>> 
>>>>>>>>>>                                    MaxBytesPerRead = FIVE_MEGABYTES
>> 
>>>>>>>>>>                            }
>>>>>>>>>>                                                                      
>>>>>>>>>>               })
>>>>>>>>>>                            
>>>>>>>>>> .Register(AllTypes.FromAssemblyContaining<IAuthenticationService>()
>>>>>>>>>>                                            .Where(type => 
>>>>>>>>>> type.Name.EndsWith(SERVICE_SUFFIX))
>>>>>>>>>>                                            
>>>>>>>>>> .WithService.FirstInterface()
>>>>>>>>>>                                            .Configure(r => 
>>>>>>>>>> NameService(r).LifeStyle.Transient),
>>>>>>>>>>                                      
>>>>>>>>>> Component.For<IServiceBehavior>()
>>>>>>>>>>                                            
>>>>>>>>>> .ImplementedBy<ServiceDebugBehavior>()
>>>>>>>>>>                                            .DependsOn(new
>>>>>>>>>>                                                            {
>>>>>>>>>>                                                                    
>>>>>>>>>> IncludeExceptionDetailInFaults = true,
>>>>>>>>>>                                                                    
>>>>>>>>>> HttpHelpPageEnabled = true,
>>>>>>>>>>                                                            }),
>>>>>>>>>>                                      
>>>>>>>>>> Component.For<IServiceBehavior>()
>>>>>>>>>>                                            
>>>>>>>>>> .ImplementedBy<ServiceMetadataBehavior>()
>>>>>>>>>>                                            .DependsOn(new
>>>>>>>>>>                                                            {
>>>>>>>>>>                                                                    
>>>>>>>>>> HttpGetEnabled = true
>>>>>>>>>>                                                            }),
>> 
>>>>>>>>>> Component.For<IServiceBehavior>().ImplementedBy<UnitOfWorkBehavior>());
>>>>>>>>>>            }
>> 
>>>>>>>>>>            #endregion
>> 
>>>>>>>>>>            private static ComponentRegistration<object>
>>>>>>>>>> NameService(ComponentRegistration<object> registration)
>>>>>>>>>>            {
>>>>>>>>>>                    var implementation = registration.Implementation;
>>>>>>>>>>                    
>>>>>>>>>> registration.Named(implementation.Name.Substring(0,
>>>>>>>>>> implementation.Name.Length - SERVICE_SUFFIX.Length)
>>>>>>>>>>                                            .ToLowerInvariant() + 
>>>>>>>>>> ".svc");
>>>>>>>>>>                    return registration;
>>>>>>>>>>            }
>>>>>>>>>>    }
>> 
>>>>>>>>>> But when I upload one I get everyone's second favorite wcf exception:
>> 
>>>>>>>>>> The formatter threw an exception while trying to deserialize the
>>>>>>>>>> message: There was an error while trying to deserialize parameter
>>>>>>>>>> http://tempuri.org/:Data. The InnerException message was 'There was 
>>>>>>>>>> an
>>>>>>>>>> error deserializing the object of type System.Byte[]. The maximum
>>>>>>>>>> array length quota (16384) has been exceeded while reading XML data.
>>>>>>>>>> This quota may be increased by changing the MaxArrayLength property 
>>>>>>>>>> on
>>>>>>>>>> the XmlDictionaryReaderQuotas object used when creating the XML
>>>>>>>>>> reader. Line 1, position 26406.
>> 
>>>>>>>>>> Is the wcf facility ignoring my DefaultBinding when using the "look 
>>>>>>>>>> no
>>>>>>>>>> config" method? Or am I doing something else wrong?
>> 
>>>>>>>>>> --
>>>>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>>>>> Groups "Castle Project Users" group.
>>>>>>>>>> To post to this group, send email to 
>>>>>>>>>> [email protected].
>>>>>>>>>> To unsubscribe from this group, send email to 
>>>>>>>>>> [email protected].
>>>>>>>>>> For more options, visit this group 
>>>>>>>>>> athttp://groups.google.com/group/castle-project-users?hl=en.
>> 
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>>> Groups "Castle Project Users" group.
>>>>>>>> To post to this group, send email to 
>>>>>>>> [email protected].
>>>>>>>> To unsubscribe from this group, send email to 
>>>>>>>> [email protected].
>>>>>>>> For more options, visit this group 
>>>>>>>> athttp://groups.google.com/group/castle-project-users?hl=en.
>> 
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Castle Project Users" group.
>>>>>> To post to this group, send email to 
>>>>>> [email protected].
>>>>>> To unsubscribe from this group, send email to 
>>>>>> [email protected].
>>>>>> For more options, visit this group 
>>>>>> athttp://groups.google.com/group/castle-project-users?hl=en.
>> 
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "Castle Project Users" group.
>>>>> To post to this group, send email to 
>>>>> [email protected].
>>>>> To unsubscribe from this group, send email to 
>>>>> [email protected].
>>>>> For more options, visit this group 
>>>>> athttp://groups.google.com/group/castle-project-users?hl=en.
>>>>> <IHateWcfConfiguration.zip>
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Castle Project Users" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to 
>>> [email protected].
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/castle-project-users?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/castle-project-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to