小弟正用remoting方式进行开发,遇到以下问题,请大虾们指点迷津:1.如果在 remoting 服务 的配置文件中设置多个信道,以及设置多个服务?
2.如何动态引用dll?
3.typeof( "obj" ) 这样作是不正确的,请问如何根据类的名字来获取类的类型?
2.如何动态引用dll?
3.typeof( "obj" ) 这样作是不正确的,请问如何根据类的名字来获取类的类型?
解决方案 »
- 如果用数据流方式读取WORD,不知道这种方式的效率高不高
- winform窗体中导出Listview中数据
- 开发桌面应用程序数据库方面如何做
- 导入到WORD
- 请问一个项目只能输出一个dll文件么,我在一个类库下添加了很多cs文件,可是把每个cs文件都编译成dll文件么?
- 新手问:VS2005中MDI问题
- 各位老大,似乎用C#的tcp延时似乎很大啊!
- 怎么会有这么怪的问题~~~~~~~~
- 在派生类中调用基类函数,构造函数,属性访问私有变量时,访问的是基类的还是派生累类继承的??
- C#问题(急啊)
- ISNet 的 WebGrid在一个不刷新的问题谢谢大侠们指点!
- 我写的C#代码好奇怪啊?想请各位看看!
typeof(t);
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" objectUri="CGroupBusiness.Soap" type="ZTE.PDM.SYS.BusinessLogic.CGroupBusiness,ZTE.PDM.SYS.BusinessLogic" />
</service>
<service>
<wellknown mode="Singleton" objectUri="CUserBusiness.Soap" type="ZTE.PDM.SYS.BusinessLogic.CUserBusiness,ZTE.PDM.SYS.BusinessLogic" />
</service>
</application>
<customErrors mode="off"/>
</system.runtime.remoting>2、通过反射加载
object System.Activator.CreateInstance(string assemblyName, string typeName)3、同样只能通过反射。
我用自己的方法做了个比较清晰点的配置文件:
<?xml version="1.0" encoding="gb2312"?>
<RemotingServer>
<RemotingConfig>
<RemotingDll>ClsFcapaComPlus.dll</RemotingDll>
<RemotingClass>WealthProCore.ClsFcapaComPlus.ClsFcapaComPlusClass</RemotingClass>
<RemotingType>tcp</RemotingType>
<RemotingHost>hekui</RemotingHost>
<RemotingPort>8090</RemotingPort>
<RemotingName>StrDOFcapa</RemotingName>
<RemotingTitle>资产配置服务(字符串传入)</RemotingTitle>
</RemotingConfig>
<RemotingConfig>
<RemotingDll>ClsFcapaComPlus.dll</RemotingDll>
<RemotingClass>WealthProCore.ClsFcapaComPlus.ClsFcapaComPlusClass</RemotingClass>
<RemotingType>tcp</RemotingType>
<RemotingHost>hekui</RemotingHost>
<RemotingPort>8091</RemotingPort>
<RemotingName>DOFcapa</RemotingName>
<RemotingTitle>资产配置服务</RemotingTitle>
</RemotingConfig>
</RemotingServer>程序中这样调用:
private bool RegServer()
{
//声明Remoting连接DLL名
string strRemotingDll = string.Empty;
//声明Remoting连接类名
string strRemotingClass = string.Empty;
//声明Remoting连接类型
string strRemotingType = string.Empty;
//声明Remoting连接主机IP或主机名
string strRemotingHost = string.Empty;
//声明Remoting连接端口
string strRemotingPort = string.Empty;
//声明Remoting连接服务名
string strRemotingName = string.Empty;
//声明Remoting连接服务说明
string strRemotingTitle = string.Empty; try
{
//xml内部读写变量
System.Xml.XmlDocument xmldoc = new XmlDocument();
//加载配置文件
xmldoc.Load( defaultServerXMLName ); //查找行节点
System.Xml.XmlNodeList xnl = xmldoc.GetElementsByTagName( "RemotingConfig" ); if (xnl.Count > 0)
{
for ( int j = 0; j < xnl.Count; j ++ )
{
for(int i =0 ; i < xnl[j].ChildNodes.Count ; i++)
{
switch( xnl[j].ChildNodes[i].Name )
{
//连接DLL名
case "RemotingDll":
strRemotingDll = xnl[j].ChildNodes[i].InnerXml;
break;
//连接类名
case "RemotingClass":
strRemotingClass = xnl[j].ChildNodes[i].InnerXml;
break;
//连接类型
case "RemotingType":
strRemotingType = xnl[j].ChildNodes[i].InnerXml;
break;
//主机IP或主机名
case "RemotingHost":
strRemotingHost = xnl[j].ChildNodes[i].InnerXml;
break;
//端口
case "RemotingPort":
strRemotingPort = xnl[j].ChildNodes[i].InnerXml;
break;
//信道服务名
case "RemotingName":
strRemotingName = xnl[j].ChildNodes[i].InnerXml;
break;
//服务说明
case "RemotingTitle":
strRemotingTitle = xnl[j].ChildNodes[i].InnerXml;
break;
default:
break;
} } //声明信道
if ( strRemotingType.ToUpper().Equals("TCP") )
{
//Tcp方式
TcpServerChannel channel = new TcpServerChannel( strRemotingName, Int16.Parse(strRemotingPort));
//注册信道
ChannelServices.RegisterChannel(channel);
}
else if( strRemotingType.ToUpper().Equals("HTTP") )
{
//Http方式
HttpServerChannel channel = new HttpServerChannel( strRemotingName, Int16.Parse(strRemotingPort));
//注册信道
ChannelServices.RegisterChannel(channel);
}
System.Console.WriteLine( strRemotingTitle + " 服务启动配置开始" ); //配置Remoting.三个参数分别为:dll类型,服务名,实例化模式(SingleCall:每次创建新实例|Singleton:使用同一实例)
Assembly a = Assembly.LoadFrom( strRemotingDll ); RemotingConfiguration.RegisterWellKnownServiceType(
a.GetType( strRemotingClass ),
strRemotingName,
WellKnownObjectMode.SingleCall
); System.Console.WriteLine( strRemotingTitle + " 服务启动配置结束" );
}
}
else
{
System.Console.WriteLine( "RemotingServer服务启动失败:配置文件错误" );
return false;
} return true;
}
catch( System.Exception ex )
{
System.Console.WriteLine("RemotingServer服务启动失败:" + ex.Message.ToString()); return false;
}
}