我有一个.NET客户机,它有几个C#库文件,其中一个c#库文件加载第三方本机库。现在,出于某些原因,我们希望将C#库转换为一个新的C#服务器进程,该进程反过来将托管和使用第三方本机库。我使用了.NET远程处理框架(HttpServerChannel)来完成这个任务。为了能够使用本机库API,我首先需要加载它的一些内部模块和应用程序。在加载应用程序时,我会得到一个SEH异常。注意:在现有体系结构中,C#库可以完成这项工作,而不是C#流程。调用如下( API用于Teigha ),SystemObjects.DynamicLinker.LoadApp("GripPoints",为true,true)
如果我错过了任何东西,因为我是.NET远程处理框架的新手,请提前道歉。
Post更新了下面的代码-加载本机库的C#库已被引用以创建新的服务器进程。服务器代码如下所示。引用的C#库是"MyClassInternal“
`using MyClassInternal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DWGServerHost
{
class DWGServerHostMain
{
public static int serverPort = 9876;
static void Main(string[] args)
{
HttpServerChannel http = null;
if (args.Length > 0 && !int.TryParse(args[0], out serverPort))
{
serverPort = 9876;
}
http = new HttpServerChannel(serverPort);
ChannelServices.RegisterChannel(http, false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyClass),
"MyClassService",
WellKnownObjectMode.SingleCall);
Thread.CurrentThread.Join();
}
}}`
在客户端,此服务将启动,然后按以下方式使用-
Process proc = new Process();
proc.StartInfo.FileName = Path.Combine("Path to Exe", "DWGServerHost.exe");
proc.StartInfo.Arguments = "9876";
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.WorkingDirectory = "Path to Server Location";
proc.Start();
//SetErrorMode(0);
if (proc.HasExited)
{
Console.WriteLine("Could not start server");
return -1;
}
HttpClientChannel http = null;
http = new HttpClientChannel();
ChannelServices.RegisterChannel(http, false);
assembly = Assembly.LoadFrom("Path to DLL");
Object obj = Activator.GetObject(typeof(MyClass), "http://localhost:9876/MyClassService");
MyClass myClass = (MyClass)obj;"MyClassInternal“库依次加载第三方库并创建服务。对于使用第三方库API,必须进行一些初始化,例如加载第三方库的内部库和模块。所使用的API是- SystemObjects.DynamicLinker.LoadApp("GripPoints", true, true)。
如果我们直接从我们的C#库客户端加载C#库,并且当承载C#库的C#服务器进程时,它就无法工作。
Note:"MyClassInternal“中的类已经从MarshalByRefObject继承过来了。所以在课堂上没有问题。
发布于 2017-10-17 10:16:20
对不起,伙计们,在做了一些更改后,我更新的主机进程没有被放置到所需的位置。我们可以结束这个问题。
https://stackoverflow.com/questions/46784018
复制相似问题