I am working with WCF and Silverlight. i want to change EndpointAddress with code behind dynamically:
EndpointAddress endpointAdress = new EndpointAddress(serviceUrl);
var proxy = new ServerConnectionClient(context);
proxy.Endpoint.Address = endpointAdress;
Connection opened successful but after call a method from service occurred ActionNotSupportedException.
Web.config:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="NetTcpBinding">
<binaryMessageEncoding />
<tcpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="net.tcp://MyIpAddress:4502/engine/net" binding="customBinding"
bindingConfiguration="NetTcpBinding" contract="CTMSConnection.IServerConnection"
name="NetTcpBinding" />
</client>
</system.serviceModel>
</configuration>
Above config generated after Add Service Reference.
Where is problem?
that is very easy. you have to generate code exactly same with Web.Config
.
you must be use the below code:
System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress("net.tcp://YourIpAddress:4502/CTMSEngine/net");
System.ServiceModel.Channels.CustomBinding customBinding = new System.ServiceModel.Channels.CustomBinding();
System.ServiceModel.Channels.BinaryMessageEncodingBindingElement BMEelement = new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement();
System.ServiceModel.Channels.TcpTransportBindingElement TcpTelement = new System.ServiceModel.Channels.TcpTransportBindingElement();
customBinding.Elements.Add(BMEelement);
customBinding.Elements.Add(TcpTelement);
TcpTelement.MaxReceivedMessageSize = 2147483647;
TcpTelement.MaxBufferSize = 2147483647;
proxy = new ServerConnectionClient(customBinding, endpointAddress);