Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用状态服务器时,如何在ASP.Net网站会话中放置IClientChannel对象?_C#_Asp.net_Wcf_Session_Serialization - Fatal编程技术网

C# 使用状态服务器时,如何在ASP.Net网站会话中放置IClientChannel对象?

C# 使用状态服务器时,如何在ASP.Net网站会话中放置IClientChannel对象?,c#,asp.net,wcf,session,serialization,C#,Asp.net,Wcf,Session,Serialization,问题是我有两台IIS服务器作为Web场工作,并使用第三台服务器作为状态服务器来处理Web场服务器之间的会话。 托管在这些IIS服务器上的网站调用WCF Webservice我使用以下代码连接到Webservice: NetTcpBinding binding = new NetTcpBinding(); binding.CloseTimeout = new TimeSpan(0, 0, 10, 0); binding.OpenTimeout = n

问题是我有两台IIS服务器作为Web场工作,并使用第三台服务器作为状态服务器来处理Web场服务器之间的会话。 托管在这些IIS服务器上的网站调用WCF Webservice我使用以下代码连接到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();
我收到了这个错误信息:

无法序列化会话状态。在“StateServer”和 “SQLServer”模式,ASP.NET将序列化会话状态对象, 因此,不可序列化对象或MarshalByRef对象是 不允许。如果存在类似的序列化,则同样的限制也适用 由自定义会话状态存储在“自定义”模式下完成


提前感谢大家的帮助:)

为什么不创建一个可序列化的对象,该对象只有您想要传输的信息?
显然,从
channel.CreateChannel()返回的是不可序列化的

更新:摘自OP的评论

通过创建实现
DataContract
ClientBase
ISerializable
的新类解决了问题。然后定义定义对象并将其放入字典的属性,以及反序列化和从字典检索对象时的属性。

问题不在于信息传输。问题是我想将代理置于会话中,以便所有Web场服务器都可以使用它,因为我使用的是循环负载平衡器。当然,但您不能将不可序列化的对象置于会话中,因为错误消息表明情况就是这样,您可能希望将所有相关信息放入不同的对象中序列化它,然后稍后从该数据中反序列化并重新初始化(如果可能的话)实际对象。是否知道通道的信息是什么,这可能是检查构造函数重写了什么以及它具有哪些可设置属性。这些是反序列化后您可以设置的,如果这些还不够,请寻找不同的方法来解决此问题。我想在会话中使用的代理是System.Runtime.Remoting.Proxies.\uu TransparentProxy类型我无法创建此类型的对象我甚至无法访问此类型对象的属性我想我卡住了
       Session["proxy"] = proxy;