我传了个Combobox过去 老是出现:
由于安全限制,无法访问类型 System.Runtime.Remoting.ObjRef。
远程对象的方法:
public void FillComboBox(ref ComboBox combo,int nIndex, int SM)
{
combo.Items.Clear();
SqlCommand command = new SqlCommand("select * from CW_Accountant_code where nIndex =" + nIndex.ToString() , Conn);
SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
combo.Items.Add(dr["SM" + SM.ToString()].ToString());
}
dr.Close();
}
客户端:
DataBaseObject dataobj = new DataBaseObject(((AccType)item.Tag).Data);
Common.DataObj = dataobj;
dataobj.FillComboBox(ref comboBox1,2, 1);
由于安全限制,无法访问类型 System.Runtime.Remoting.ObjRef。
远程对象的方法:
public void FillComboBox(ref ComboBox combo,int nIndex, int SM)
{
combo.Items.Clear();
SqlCommand command = new SqlCommand("select * from CW_Accountant_code where nIndex =" + nIndex.ToString() , Conn);
SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
combo.Items.Add(dr["SM" + SM.ToString()].ToString());
}
dr.Close();
}
客户端:
DataBaseObject dataobj = new DataBaseObject(((AccType)item.Tag).Data);
Common.DataObj = dataobj;
dataobj.FillComboBox(ref comboBox1,2, 1);
没必要要ref
namespace RemoteObject
{
[Serializable]
#region 数据类
public class DataBaseObject : MarshalByRefObject
{
}
#endregion
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />另外[Serializable]是不用的
RemotingConfiguration.RegisterActivatedServiceType(typeof(DataBaseObject));
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterActivatedClientType(
typeof(DataBaseObject), "tcp://192.168.0.15:8000/RemoteObject");
DataBaseObject dataobj = new DataBaseObject(((AccType)item.Tag).Data);
Common.DataObj = dataobj;
下面的列表描述 .NET 远程处理反序列化级别: Low(默认级别)
.NET 远程处理中的默认反序列化级别支持以下类型的反序列化: 远程处理基础结构对象。它们是在基本级别进行远程处理时所需的类型。
基元类型以及由基元类型构成的引用类型和值类型。
用 SerializableAttribute 属性标记但未实现 ISerializable 接口的引用类型和值类型。
实现 ISerializable 并且未发出序列化之外的其他任何要求的系统提供类型。
实现 ISerializable(或者用 SerializableAttribute 标记)并位于未用 AllowPartiallyTrustedCallersAttribute 属性标记的程序集中的系统提供类型。
具有强名称并且位于未用 AllowPartiallyTrustedCallersAttribute 属性标记的程序集中的自定义类型。
实现 ISerializable 并且未发出序列化之外的其他任何要求的自定义类型。
实现 ILease 接口并且不属于 MarshalByRefObject 对象的类型。
用于激活(以支持客户端激活的对象)的 ObjRef 对象;也就是说,客户端可以反序列化返回的 ObjRef,但服务器却不能。
Full
.NET 远程处理中的 Full 反序列化级别支持其他所有方案,包括以下附加类型的反序列化: 作为参数传递的 ObjRef 对象。
实现 ISponsor 接口的对象。
由 IContributeEnvoySink 接口在代理和客户端管线之间插入的对象。
如果应用程序需要使用仅在 Full 反序列化级别才可用的远程处理功能,您必须提供身份验证的类型和必要的加密级别,以保护任何在使用远程方案中的这些高级功能时可能遭受风险的资源。 您可以通过编程方式或使用应用程序配置文件设置反序列化级别。以编程方式设置反序列化级别
若要以编程方式设置反序列化级别,请在创建时将以下属性传递给 SoapServerFormatterSinkProvider 对象或 BinaryServerFormatterSinkProvider 对象。然后,当该值插入到接收链中时,远程处理系统将在格式化程序上设置该值。以下示例说明如何在宿主应用程序域中将反序列化级别设置为 Full。[C#]// Creating a custom formatter for a TcpChannel sink chain.BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();provider.TypeFilterLevel = TypeFilterLevel.Full;// Creating the IDictionary to set the port on the channel instance.IDictionary props = new Hashtable();props["port"] = 8085;// Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.)TcpChannel chan = new TcpChannel(props, null, provider);[Visual Basic]' Creating a custom formatter for your TcpChannel sink chain.Dim provider As New BinaryServerFormatterSinkProvider()provider.TypeFilterLevel = TypeFilterLevel.Full' Creating the IDictionary to set the port on the channel instance.IDictionary props = new Hashtable()props("port") = 8085' Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.)Dim chan As New TcpChannel(props, null, provider)
现在错误变这样了服务端:
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider(); provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; // Creating the IDictionary to set the port on the channel instance. IDictionary props = new Hashtable(); props["port"] = 8000; // Pass the properties for the port setting and the server provider in the server chain argument. (Client remains null here.) TcpChannel Channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(Channel);
是否不能传递ComboBox combo这个东西过去?