Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>AutoCAD can't work with document object from external thread. That's the root of the problem. If I write method and put an CommandMethodAttribute - it will be work, but only from AutoCAD console... But, what if I need to do this operations from external application? First of all, need to specify the attribute on service behavior class</p> <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)] </code></pre> <p>Thus be used only one thread for all operations.</p> <p>The next step, in <code>Initialize()</code> method get the CurrentDispatcher object and put it in static variable.</p> <pre><code>private static Dispatcher dispatcher; public void Initialize() { dispatcher = Dispatcher.CurrentDispatcher; this.host = new ServiceHost(typeof(Printer), new[] { new Uri("net.pipe://localhost") }); this.host.AddServiceEndpoint(typeof(IConnector), new NetNamedPipeBinding(), "GetPdfVersion"); this.host.Open(); } </code></pre> <p>by this way, control of autocad execution context can be achieved. The next step is invoke the method through dispatcher</p> <pre><code>public void GetPdfVersion(string filePath, string exportFilePath) { dispatcher.Invoke(new Action&lt;string, string&gt;(this.GetPdfVer), filePath, exportFilePath); } </code></pre> <p>So, by using this method, I can run code, contained in <code>GetPdfVer</code> method from external application and get all benefits of using WCF instead of COM-interaction.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload