Why we need to change “AddressFilterMode” on Windows Azure.

 

Few days back I had firsthand experience where on-premise services stopped working when I hosted them on Windows Azure. After doing some digging I found that I’ve to change service behavior by adding [ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]. It worked but why? I did some research and here is my version of why we have to change AddressFilterMode.Any or AddressFiterMode=Prefix. (During my investigation I found that AddressFiterMode=Prefix also works) Let me know if it is correct:

 

Each WCF service endpoint has two addresses associated with it, logical and physical address (usually these two addresses are same). The logical address is “To” and physical address is “Via” and it is specified using WS-Addressing. WCF channel received incoming message using a particular transport at a specific physical address location. The WCF Dispatch maps the incoming message to an endpoint.  The message filter is used by dispatcher to determine the matching logical address/endpoint-address. The dispatch filters looks at address and contract calls the right method.

 

On Windows Azure the public facing endpoints are actually Load-blance-endpoints. This means when a message arrives at the LB, it routes the message to the actual instance where is service is hosted. Now the SOAP message had endpoint which was LB-endpoint but the instance which actually processed the message was different. WCF match dispatcher filter tries to match the endpoint address and it fails.

Therefore on windows azure we have to relax prefix match on the address of an incoming message and must relax the message filter rule at the message dispatch level by using AddressFiterMode=Any or AddressFiterMode=Prefix.

 

References:

http://msdn.microsoft.com/en-us/magazine/cc163412.aspx

http://msdn.microsoft.com/en-us/library/system.servicemodel.addressfiltermode.aspx