I need help converting the following netTcpBinding to an equivalent CustomBinding:
<bindings>
<netTcpBinding>
<binding name="secureNetTcp" openTimeout="00:00:25" closeTimeout="00:00:27" receiveTimeout="00:10:10" sendTimeout="00:01:00"
listenBacklog="50" maxBufferPoolSize="2097152" maxBufferSize="2097152" maxConnections="50" maxReceivedMessageSize="2097152">
<readerQuotas maxArrayLength="2097152" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true" />
<security mode="TransportWithMessageCredential">
<message algorithmSuite="Basic256Sha256" />
</security>
</binding>
</netTcpBinding>
</bindings>
I’m mostly struggeling with the Security part of the custom binding, because I can’t fathom all the different settings. And everything seems to be named differently as well (compared to netTcpBinding parameters).
In case it’s necessary I’ll provide the following information as well:
The service endpoint has a certificate attached to it via serviceBehavior.
In my code I provide a username/password when creating the proxy (service behavior has <userNameAuthentication userNamePasswordValidationMode="Windows" /> under serviceCredentials; For the netTcpBinding the WCF configuration editor shows ClientCredentialType=Windows, which I guess is the default value).
Update:
I have found a potential solution for my main problem – increasing ChannelInitilizationTimeout – without having to create a CustomBinding. I’ll share this, incase someone stumbels upon this thread while googeling…
What I did was create a custom class that inherits from NetTcpBinding and in it’s constructor used reflection to set the ChannelInitilizationTimeout property. Thus maintaining full compatibility with NetTcpBinding.
Here is the code for my custom class:
public class MyNetTcpBinding : NetTcpBinding
{
public MyNetTcpBinding()
{
var fi = typeof(NetTcpBinding).GetField("transport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var val = (System.ServiceModel.Channels.TcpTransportBindingElement)fi.GetValue(this);
val.ChannelInitializationTimeout = TimeSpan.FromSeconds(10);
}
}
public class MyBindingElement : NetTcpBindingElement
{
protected override Type BindingElementType
{
get { return typeof(MyNetTcpBinding); }
}
}
public class MyBindingElementCollection : StandardBindingCollectionElement<MyNetTcpBinding, MyBindingElement>
{
}
After compiling this class (I created a seperate DLL project for this class), I used WCF configuration editor (under left pane “Configuration” -> Advanced -> Extensions -> binding extensions -> new -> give a name, eg. “MyNetTcp” and point to the dll file) to add my class as an extension to bindings.
Afterwards in WCF app.config just replace netTcpBinding with MyNetTcp (there are three references in total; one in <service><endpoint binding="netTcpBinding"></endpoint></service>; the other two are xml tags under <bindings><netTcpBinding></netTcpBinding></bindings>).
I will leave this question open in case someone wants to give a proper answer to the original question…
You can pass in the netTcpBinding into a custom binding and do the following.
There is no guarantee that reflection will work across versions.
http://blogs.msdn.com/b/sajay/archive/2010/01/29/how-to-create-a-custom-binding-from-a-standardbinding.aspx