Sometimes, you need to bind some new tech with old stuff. In this case, we create a WCF service called by an ASMX client (true story, bro).

First important knowlodge: difference between BasicHttpBinding and WsHttpBinding. Below, a summarizing table. As you can see, in this case you have to use BasicHttpBinding.

Criteria BasicHttpBinding WsHttpBinding
Security support This supports the old ASMX style, i.e. WS-BasicProfile 1.1. This exposes web services using WS-* specifications.
Compatibility This is aimed for clients who do not have .NET 3.0 installed and it supports wider ranges of clients. Many of the clients like Windows 2000 still do not run .NET 3.0. So older version of .NET can consume this service. As its built using WS-* specifications, it does not support wider ranges of client and it cannot be consumed by older .NET version less than 3 version.
Soap version SOAP 1.1 SOAP 1.2 and WS-Addressing specification.
Reliable messaging Not supported. In other words, if a client fires two or three calls you really do not know if they will return back in the same order. Supported as it supports WS-* specifications.
Default security options By default, there is no security provided for messages when the client calls happen. In other words, data is sent as plain text. As WsHttBinding supports WS-*, it has WS-Security enabled by default. So the data is not sent in plain text.
Security options
  • None
  • Windows – default authentication
  • Basic
  • Certificate
  • None
  • Transport
  • Message
  • Transport with message credentials

Ok, so, here the steps to reach our goal:

    1. Usage of basicHttpBinding for the service binding
    2. Removal of MEX endpoint for enabling windows authentication (I skipped this, I don’t need windows auth)
    3. Usage of XmlSerializerFormat attribute to enable proper messaging format
      Example:

      
      [ServiceContract]
      [XmlSerializerFormat(Use = OperationFormatUse.Literal, Style = OperationFormatStyle.Document)]
      public interface IStockService
      {
      
      
      [OperationContract(Action = “http://tempuri.org/GetStockValue”, ReplyAction = “http://tempuri.org/GetStockValue”)]
      int GetStockValue(string stockSymbol);
      
      
      [OperationContract(Action = “http://tempuri.org/GetCompanyDetails”, ReplyAction = “http://tempuri.org/GetCompanyDetails”)]
      Company GetCompanyDetails(string stockSymbol);
      }
      
    4. Usage of Action/ReplyAction parameters to provide namespace support (see the above sample, these parameters are used there)

 

These simple steps make your WCF able to receive request from an ASMX client.

 

Advertisements