Need help converting WCF netTcpBinding to CustomBinding

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 mainly deal with protecting part of the user binding, because I cannot understand all the different settings. And everything seems to be named differently (compared to the netTcpBinding parameters).

If necessary, I will also provide the following information:
The service endpoint has a certificate attached to it through serviceBehavior.
In my code, I specify the username / password when creating the proxy (the service behavior has <userNameAuthentication userNamePasswordValidationMode="Windows" /> in serviceCredentials; for netTcpBinding, the WCF configuration editor shows ClientCredentialType=Windows , which I assume is the default value).

Update:

I found a potential solution to my main problem - increasing ChannelInitilizationTimeout - without having to create a CustomBinding. I will share this if someone stumbles upon this thread while I walk ...

What I did was create a custom class that inherits from NetTcpBinding , and in it the 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 separate DLL project for this class), I used the WCF configuration editor (in the left pane "Configuration" → Advanced → Extensions → Binding Extensions → new → give a name, for example, “ MyNetTcp ” and specify the dll file) to add my class as an extension for bindings.

Subsequently, in WCF app.config, simply replace netTcpBinding with MyNetTcp (there are only three links: one in <service><endpoint binding="netTcpBinding"></endpoint></service>; other two are xml tags under <bindings><netTcpBinding></netTcpBinding></bindings> ).

I will leave this question open if someone wants to give the correct answer to the original question ...

+4
source share
1 answer

You can pass netTcpBinding to a user binding and do the following. There is no guarantee that reflection will work in different versions.

http://blogs.msdn.com/b/sajay/archive/2010/01/29/how-to-create-a-custom-binding-from-a-standardbinding.aspx

0
source

Source: https://habr.com/ru/post/1395688/


All Articles