Common WWSAPI errors: wrong property value size
WWSAPI properties are designed to control the behavior of the WWSAPI objects like service proxy, channel, XML reader/writer, etc. Each property has a property id, an associated value type, a target object and allowed actions. All property structures have the same set of fields: a property id, a pointer to the value buffer and the size of the buffer. The property accessors follow the same design as well. When using WWSAPI properties, it’s important to know these rules:
1. Only use in allowed functions: some properties can be used at creation time only while some can be set and get at any point of the object’s lifetime.
2. Set the right value size
E_INVALIDARG (0x80070057) will be returned if either of the rules are broken. More than once I heard customer asking: “My codes works fine in x86 version. I get E_INVALIDARG when running x64 version”. The problem turned out to be that the property value size was wrong. The property value type was SIZE_T (e.g. WS_SERVICE_ENDPOINT_PROPERTY_BODY_HEAP_MAX_SIZE), which has different size on 32-bit and 64-bit build. The bug in code was that the actual property value was defined as ULONG (4 bytes) instead of SIZE_T. The property code checks the value size passed in against the expected size and returns E_INVALIDARG if they don’t match. Since SIZE_T is 4-byte in 32-bit build and 8-byte in 64-bit build, using ULONG will work fine on x86 machine but break on x64 machine.
The other similar error is the use of the type bool for properties with type BOOL. The builtin type bool in the newer VS++ compilers has 1 byte, whereas the Windows type BOOL has 4 bytes.