This is a mirror of official site: http://jasper-net.blogspot.com/

WCF Custom Binding

| Sunday, August 21, 2011
Introduction

In certain scenario you must create your own binding for additional transport protocols, security etc. In WCF, you can easily create the custom bindings using the configuration and custom implementations. Go through the following options for more information. This is same as my original post WCF Custom Binding
Option 1 : Using Configuration

<customBinding>
    <binding name="myCustomHttpBinding">
        <binaryMessageEncoder />
        <httpTransport / >
    </binding >   
</customBinding >

Option 2 : Programmatically

// create the custom binding object
CustomBinding myBinding = new CustomBinding();

// add the custom binding elements
myBinding.Elements.Add(new BinaryMessageEncodingBindingElement());
myBinding.Elements.Add(new HttpTransportBindingElement());

// add the service endpoint
ServiceHost host = new ServiceHost(typeof(HelloService));
ServiceEndpoint serviceEndpoint =
         host.AddServiceEndpoint(typeof(IHelloService),
                           myBinding,
                           "http://localhost:8080/HelloService");
                          
// service is ready for user
host.Open();

Option 3: Custom Implementation

public class MyCustomBinding : Binding
{
    private HttpTransportBindingElement transport;
    private BinaryMessageEncodingBindingElement encoding;

    public MyCustomBinding()
           : base()
    {
      this.InitializeValue();
    }


Read more: Codeproject
QR: WCF-Custom-Binding.aspx

Posted via email from Jasper-net

0 comments: