问题概要:
在正常情况下, A 类调用了 B 类的方法,一切正常,可是当把 B 放在 Remoting 端,则A通过 tcp channel 调用 B 类的方法时,出现无限阻塞现象,今天碰到一例不知为何,太希望得到解决了问题详细论述:Client 类的 Main 方法,调用了 远程的 Compiler 类的 GetGuid() 方法
下面是 GetGuid() 的方法实现public string GetGUID(string dllpath)
{
//TLI 命名空间来自一个 动态链接库:C:\WINNT\system32\TLBINF32.DLL
//可以用加载引用的方式加载进来
TLI.TLIApplicationClass tliapp = new TLI.TLIApplicationClass();
TLI.TypeLibInfo info = tliapp.TypeLibInfoFromFile(dllpath);
return info.GUID;
}需要着重说明的是:程序在 方法的第一行阻塞,即: new TLI.TLIApplicationClass() 处,不知为何?下面是详细的源代码:---------------------------远程对象-------------------------------
public class Compiler : MarshalByRefObject
{
public Compiler()
{
}
public string GetGUID(string dllpath)
{
TLI.TLIApplicationClass tliapp = new TLI.TLIApplicationClass();
TLI.TypeLibInfo info = tliapp.TypeLibInfoFromFile(dllpath);
return info.GUID;
}
}---------------------------服务器端-------------------------------
class Class1
{
static void Main(string[] args)
{
try
{
RemotingConfiguration.Configure("RemoteCompiler.exe.config");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
---------------------------RemoteCompiler.exe.config 配置文件-------------------------------<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<activated type="RemoteCompiler.Compiler,RemoteCompiler"/>
<wellknown mode="Singleton"
type="RemoteCompiler.Compiler,RemoteCompiler"
objectUri="Compiler.soap"/>
</service>
<channels>
<channel port="13102" ref="tcp"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>---------------------------客户端-------------------------------
class Client
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
string url = "tcp://localhost:13102";
//当隐掉下面这一行时,调用正常
RemotingConfiguration.RegisterActivatedClientType(typeof(RemoteCompiler.Compiler),url);
Compiler c = new Compiler();
string guid = c.GetGUID(@"C:\WINNT\system32\STDOLE2.TLB");
Console.WriteLine(guid);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}还需要说明的是当我把客户端的下面一行隐掉的话:
RemotingConfiguration.RegisterActivatedClientType(typeof(RemoteCompiler.Compiler),url);
则程序可以正常通过,显然这是在调用本地方法.是不是和那个类库方法有关系呢?
如果实在不行的话,有没有什么别的方法可以得到一个动态链接库的GUID 和版本信息呢?拜托各位学哥学姐,帮帮忙了,小弟快要受不了!
http://blog.csdn.net/ChengKing/archive/2005/10/26/517349.aspx
还是不要玩的好,而且问题多多 比如服务端为什么就取不到客户端ip那?
作为服务端最起码的要求都没有(想写点日至也写不了),悲哀 期待下一个版本改进,或者告诉大家不要用了快废除了也好
TLI.TLIApplicationClass tliapp = new TLI.TLIApplicationClass();
可是却不明白为什么在本地是可以正常调用的.