2017-10-17 82 views
0

我有一個.NET客戶端,它具有多個C#庫文件,其中一個C#庫文件加載第三方本機庫。現在由於某些原因,我們希望將C#庫轉換爲新的C#服務器進程,該進程又將託管第三方本機庫並使用它。 我已經使用.NET Remoting框架(HttpServerChannel)來完成此操作。爲了能夠使用本地庫API,我首先需要加載它的一些內部模塊和應用程序。加載應用程序時,我得到一個SEH異常。 注意:這與我現有的C#庫執行此作業而不是C#進程的現有體系結構正常工作。 電話是類似下面(API的使用Teigha服務使用) SystemObjects.DynamicLinker.LoadApp(「GripPoints」,真,真)在C#服務器進程中加載​​應用程序時拋出SEHException

道歉提前如果我錯過了什麼,因爲我是新來的。 NET REMOTING框架。

發佈已更新,代碼如下 - 加載本地庫的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)

上述API的工作完美的,如果我們直接從我們的C#庫客戶端加載C#庫,它不工作時,託管C#庫的C#服務器進程。

注意:「MyClassInternal」中的類已經從MarshalByRefObject繼承。所以在課堂上沒有問題。

+0

請給我們一些代碼。 – Lamar

+0

Hi Lamar,用代碼更新了帖子 – GeeKay

回答

0

對不起人們,我做了一些更改後,我的更新主機進程沒有被放置到所需的位置。 我們可以關閉這個問題。

相關問題