views:

315

answers:

1

I'd like to configure a NetTcpBinding programatically for a silverlight 4 client. (NetTcpBinding is now supported)

Here is the code I use to do this for a Windows Forms client:

  EndpointAddress endpointAddress = new EndpointAddress(uri);
  NetTcpBinding netTcpBinding = new NetTcpBinding();
  MyServiceClient agentClient = new MyServiceClient(new InstanceContext(this), netTcpBinding, endpointAddress);

For silverlight I added references to System.ServiceModel.Extensions and System.ServiceModel.NetTcp, but this is not not enough : I'm not able to find a NetTcpBinding class.

Where is this class if it exists? Does an equivalent syntax exists? The silverlight 4 runtime must be doing this somehow when a configuration file is used.

+1  A: 

You can use a custom binding in place of NetTcpBinding : the code below is working, but I don't know if this is the recommended pattern.

  BinaryMessageEncodingBindingElement messageEncoding = new BinaryMessageEncodingBindingElement();
  TcpTransportBindingElement tcpTransport = new TcpTransportBindingElement();
  CustomBinding binding = new CustomBinding(messageEncoding, tcpTransport);
olorin
I did a bit of research and compared to some native non-Silverlight clients, and this definitely looks like the recommended pattern for programmatically creating a netTcpBinding in Silverlight 4.
dlanod