The problem is I have 2 IIS Servers working as Web Farm and using third Server as State Server for Session Handling between Web Farm Servers.
The Website hosted on these IIS Server calls WCF Webservice I use this Code to connect to Webservice:
NetTcpBinding binding = new NetTcpBinding();
binding.CloseTimeout = new TimeSpan(0, 0, 10, 0);
binding.OpenTimeout = new TimeSpan(0, 0, 10, 0);
binding.ReceiveTimeout = new TimeSpan(0, 0, 10, 0);
binding.SendTimeout = new TimeSpan(0, 0, 10, 0);
binding.PortSharingEnabled = true;
EndpointAddress address = new EndpointAddress("net.tcp://x.x.x.x/TestService.svc");
ChannelFactory<ICustomer> channel = new ChannelFactory<ICustomer>(binding, address);
channel.Credentials.Windows.ClientCredential.Domain = "test.com";
channel.Credentials.Windows.ClientCredential.UserName = "usr";
channel.Credentials.Windows.ClientCredential.Password = "pass";
var proxy = channel.CreateChannel();
Everything is working fine. The problem is I need to put the webservice Proxy in the ASP.net Website Session Knowing that I'm using State Server so the object which I put in the Session must be Serializable. The question is how to make the 'proxy' variable serializable so I can put it in the Session of the State Server. please note that I used this code :
Session["proxy"] = proxy;
And I got this error Message :
Unable to serialize the session state. In 'StateServer' and
'SQLServer' mode, ASP.NET will serialize the session state objects,
and as a result non-serializable objects or MarshalByRef objects are
not permitted. The same restriction applies if similar serialization
is done by the custom session state store in 'Custom' mode.
Thank you guys for your help in Advance :)