共用方式為


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>

Comments

  • Anonymous
    November 05, 2008
    PingBack from http://www.tmao.info/wwsapi-to-wcf-interop-2-default-basichttpbinding/

  • Anonymous
    April 06, 2009
    Below you may links to resources available for connecting C/C++ code and Web Services using Windows Web

  • Anonymous
    September 04, 2011
    Thank you!  Thanks to this entry, I have managed to create a working wsdl client that gets the Currency rate from webservicex. I used the sample code that I found at msdn.microsoft.com/.../dd323328(v=VS.85).aspx This was the code that I needed to make it work

  • Anonymous
    June 01, 2012
    Also thanks from my side. I did about the same as Fredrik Wahlgren. Instead I tried GetStockQuote from WebserviceX, by starting with the Microsoft sample code. The above given additional code proofs to be essential to get a HTTP-request to www.webservicex.net/stockquote.asmx working.