WWSAPI to WCF interop 2: default BasicHttpBinding

WCF's BasicHttpBinding is conformant to Basic Profile 1.1. That is, BasicHttpBinding uses SOAP version 1.1 and no WS-Addressing. The message intent is carried in the SOAPAction header. If you have read my previous post, you’ve probably realized that the default WWSAPI settings (SOAP version 1.2 and WS-Addressing 1.0) don’t match these two in BasicHttpBinding. Therefore, in order to communicate with a WCF endpoint with default BasicHttpBinding (see note below), you’d have to change SOAP version and the WS-Addressing version through the channel properties.

Here is how channel properties can be set:

WS_CHANNEL_PROPERTY channelProperties[4]; // hold up to 4 channel properties

ULONG channelPropertyCount = 0;

WS_ENVELOPE_VERSION soapVersion = WS_ENVELOPE_VERSION_SOAP_1_1;

channelProperties[channelPropertyCount].id = WS_CHANNEL_PROPERTY_ENVELOPE_VERSION;

channelProperties[channelPropertyCount].value = &soapVersion;

channelProperties[channelPropertyCount].valueSize = sizeof(soapVersion);

channelPropertyCount++;

WS_ADDRESSING_VERSION addressingVersion = WS_ADDRESSING_VERSION_TRANSPORT;

channelProperties[channelPropertyCount].id = WS_CHANNEL_PROPERTY_ADDRESSING_VERSION;

channelProperties[channelPropertyCount].value = &addressingVersion ;

channelProperties[channelPropertyCount].valueSize = sizeof(addressingVersion );

channelPropertyCount++;

// add more channel properties here

Then you pass the channelProperties and channelPropertyCount to WsCreateServiceProxy (or WsCreateChannel if you are working at channel layer).

// Create the proxy

hr = WsCreateServiceProxy(

WS_CHANNEL_TYPE_REQUEST,

WS_HTTP_CHANNEL_BINDING,

NULL, // security description

NULL, // proxy properties

0, // proxy property count

channelProperties, // channel properties

channelPropertyCount, // channel property count

&proxy,

error);

Since the properties are copied in WsCreateServiceProxy, the caller can free the memory of the property array right after the WsCreateServiceProxy call. If you are allocating the memory from stack like the code snippet above, you can return from the function right after WsCreateServiceProxy. In fact, this is true for all WsCreate* APIs.

Note: a default BasicHttpBinding is created by new BasicHttpBinding() in code or represented by the following binding element in config:

      <basicHttpBinding>

        <binding name="default" />

      </basicHttpBinding>