IntroductionIn 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 Implementationpublic class MyCustomBinding : Binding
{
private HttpTransportBindingElement transport;
private BinaryMessageEncodingBindingElement encoding; public MyCustomBinding()
: base()
{
this.InitializeValue();
}
Read more: Codeproject
QR:
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 Implementationpublic class MyCustomBinding : Binding
{
private HttpTransportBindingElement transport;
private BinaryMessageEncodingBindingElement encoding; public MyCustomBinding()
: base()
{
this.InitializeValue();
}
Read more: Codeproject
QR:
0 comments:
Post a Comment