.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

WCF and Autocad P&ID, eNotApplicable error

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
110000474593
1410 Views, 18 Replies

WCF and Autocad P&ID, eNotApplicable error

Hello everyone,

 

I have a problem with implementing WCF in Autocad P&ID 2014. I've downloaded the trial version of P&ID 2014 to run some test with it. I want to talk to the Autcad application with an external windows aplication. With the help of this example, I've managed it to open Autocad with the external applicatoin. I also created some self made Commands by creating .dll files and NETLOAD them into Autocad. All works fine as I expected. After that, I want to use WCF to talk to the Autocad application. I watched the lesson of Paul Schleppy, which is recommanded in this discussion. I get the WCF service working in Autocad and I can send messages to it without any problems. The service is hosted inside autocad.

 

The only thing is: When I want to talk to the 'CurrentDocument' of Autocad, I get the following error: eNotApplicable. This error occurs for an example, when I want to send something to the editor of the CurrentDocument. But also when I want to open the database of the CurrentDocument. An expert on .NET programming with Autocad tells me this is because I want to use UI dependent functions on a background thread, which are only available on the UI thread. He said I must avoid this kind of functions. But that means I can't do anything with the CurrentDocument?? He also gave another solution. He says I have to store the UI SynchronizationContext at the startup of the host and then use the UI dependent functions with a 'Post' or 'Send'. But that isn't working either, I still get the eNotApplicable error.

 

He said the problem could be the trial version of Autocad P&ID 2014, because sometimes trail versions acting weird.

 

Now I'am curious: Do you have other solutions? Or do you have other experiences with WCF and Autocad and how do you work this out? I really want to make this working.

 

I have attached my Visual Studio solution. It contains three projects. One host, one service and one client (a little Winform app). I use VS2012 on a 64-bit laptop. Befor you build the soluton, make shure you change the IP adress in the 'Form1' class of the client. Once you build the solution, first NETLOAD the host in Autocad and then the service. Then use the following command: "AutoHostAutocadService". Now the service is listening. After that, you can attach youre VS to Autocad and the you can press F5 for debugging. A little winform app will start. Type something in the textbox and click the button. If you have set a breakpoint in the constructor of the 'FindTag' class, this breakpoint will hit. In the constructor, the eNotApplicable is raised by writing a message to the editor.

 

Please, can anyone help me?

Tags (3)
18 REPLIES 18
Message 2 of 19
110000474593
in reply to: 110000474593

For clarity, this error only appears when I work with WCF. I don't get this error when I use my self made commands.

Message 3 of 19
sszabo
in reply to: 110000474593

You probably have to solve the multithreading issue I encountered when I was trying to do the same.  Check out this thread

Message 4 of 19
110000474593
in reply to: sszabo

Hi sszabo,

 

Thanks for your reply. I already looked at that thread two weeks ago, but I didn't get it working. Maybe I'm going to look at it another time again.

Do you have it working now? You first also get the eNotApplicable error? Is there another way to use WCF with autocad or do you use the same way as I?

 

Thanks in advance.

Message 5 of 19
sszabo
in reply to: 110000474593

eNotApplicable just means you are trying to access the dwg DB from a service response which is running in a different thread than your IEXtensionApplication.

 

All you have to do is create a new VB class project and copy/paste the code into it, add the usual references, (make sure you remove double space ow attribute refs will not compile) , compile the DLL and it should netload and start the WCF service.  I am using this template for actual projects and it works.  If you get stuck let me know where, chances are I can help you out.

 

Here is the list of references you'll have to add to your project:

 

accoremgd

acdbmgd

acmgd

Autodesk.AutoCAD.Interop

Autodesk.AutoCAD.Interop.Common

System.Runtime.Serialization

System.ServiceModel

System.Windows.Forms

 

 

Message 6 of 19
sszabo
in reply to: 110000474593

BTW, I just downloaded and took a quick look at your code, I think now I remeber the issue, I struggled with it myself.  The bottom line: Editor access has to be from the main thread.  Again take a look at my logMessage function.

Message 7 of 19
fenton.webb
in reply to: sszabo

Use Dispatcher.beginInvoke()




Fenton Webb
AutoCAD Engineering
Autodesk

Message 8 of 19
sszabo
in reply to: fenton.webb

I tried that like this, it didn't work for me (no exceptions, but never saw the message either)

 

                Action action = () =>
                {
                    fDocument.Editor.WriteMessage("Hello, this is FindTag : IFindTag");
                };
                Dispatcher.CurrentDispatcher.BeginInvoke(action);

Message 9 of 19
sszabo
in reply to: sszabo

I have to issue a correction to my earlier post!  (I am using Adam Nagy's solution for this) it's not that your call has to be in the main thread, rather it has to go through the Invoke method of a Control, at least that's what worked for me, but if you can make Fenton's idea work that certainly looks more elegant since your FindTag class won't even have to inherit from Control.

Message 10 of 19
110000474593
in reply to: fenton.webb

Hi Fenton,

 

Thanks for your reply. I did a web search on 'Dispatcher.beginInvoke()'. Is it true that this used in WPF, and not in Winforms? Because in Winforms we have the 'Control.BeginInvoke' method. I can't use Dispatcher.beginInvoke() because there is no reference for Winforms called 'System.Windows.Threading'. Also adding the 'Windows.Base' reference isn't working. So how would I implement this?

Message 11 of 19
sszabo
in reply to: 110000474593

Made some modifications to your service class: added a helper class clsFindTag that inherits from Control.  This seems to be working. Let me know if you have questions.

Message 12 of 19
nirmalya23
in reply to: 110000474593

Hi, You must solve the multithreading issues to get out of this type of errors.

Message 13 of 19
fenton.webb
in reply to: 110000474593

If you can get it working using WinForms Control.BeginInvoke() then no problem. I prefer WPF myself. It's totally fine to mix both technologies by adding the WPF references.




Fenton Webb
AutoCAD Engineering
Autodesk

Message 14 of 19
sszabo
in reply to: 110000474593

I concur.

 

If you replace in my previous attachment clsFindTag with wpfFindTag bellow, it works the same.  You have to inherit from UserControl however!

 

    public class wpfFindTag : UserControl
    {
        public Editor ed = null;
        public void PrintMessage(String msg)
        {
            Action action = () =>
            {
                ed.WriteMessage("Hello, this is FindTag : IFindTag={0}", msg);
            };
            Dispatcher.CurrentDispatcher.BeginInvoke(action);
        }
    }

Message 15 of 19
110000474593
in reply to: sszabo

Hi sszabo,

Thank you so much for your help, it is working now!! However, I still get some time-out and connection errors (TCP error code 10061) sometimes. Mabye I have to change some settings in my firewall and ports? And it takes about 20 seconds before my text appears in the editor. Is your WCF service working fast?

Fenton, you also thanks for your help!
Message 16 of 19
sszabo
in reply to: 110000474593

20 seconds?! that doesn't sound right.  Are you getting this timeout while running your client on the same machine as server or from a remote machine, is it working on the same machine? can you post the exceptions you are getting?!  I am on AutoCAD 2013 and it works fine for me running on the same machine whith the code I attached above and I used both WCFTestClient and your client to confirm this.

 

I see this code in your client that obviously will not work anywhere except on one machine:

EndpointAddress ep = new EndpointAddress("net.tcp://192.168.1.42:8025/ACADWCF.Services/FindTag/");

 

Also, if it works on 1 machine and it doesn't work on another chances are it's because of a default web config file.  You should really have a <system.serviceModel> section in your app.config that you obtain from running:

C:\svcutil /language:cs  /out:ACADWCFProxy.cs /config:ACADWCF.exe.config net.tcp://192.168.1.42:8025/ACADWCF.Services/FindTag

 

Also, if any of the posts in this thread contain the solution can you please mark it as response, thanks.

Message 17 of 19
110000474593
in reply to: sszabo

Yes, I'm running my client on the same machine as the service. I changed the IP adress in my endpointAddress to '(localhost)', so that should be working.

Is the web config file created by visual studio automatically? If yes, which one is it? If have af file called 'ACADWCF.Services.dll.config' in my ACADWCF debug directory. I've attached this file.

I'm not familiar with command you mention. Where should I run the command you mention in your post?

Message 18 of 19
sszabo
in reply to: 110000474593

Yes, I'm running my client on the same machine as the service. I changed the IP adress in my endpointAddress to '(localhost)', so that should be working.

 

use 127.0.0.1 everywhere just to be sure.

If have af file called 'ACADWCF.Services.dll.config' in my ACADWCF debug directory. I've attached this file.

 

There are several problems with the config file you sent me.  First of all it's using the wrong protocol (http) your service is net.tcp.  Too many issues to list them all.  Remove this file and replace it with svcutil output.  Alternatively just replace the whole system.serviceModel section in this file with the following:

 

    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IFindTag" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://192.168.1.42:8025/ACADWCF.Services/FindTag/"
                binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IFindTag"
                contract="IFindTag" name="NetTcpBinding_IFindTag" />
        </client>
    </system.serviceModel>

Make sure the IP address matches your machine and this was created with the service version I attached in my response above!


I'm not familiar with command you mention. Where should I run the command you mention in your post?

 

To find this tool on your system type in where svcutil in Visual Studio Command Prompt. On my system it's:

C:\Program Files (x86)\Microsoft Visual Studio 11.0>where svcutil
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\SvcUtil.exe


It is crucial that you read the basics on svcutil and WCFTestClient if you are planning on dealing with WCF in the future: it will save you a lot of headache. Google both of these, I can't send you MSDN links, these pages are down for some reason but it used to be here:

http://msdn.microsoft.com/en-us/library/aa347733.aspx

If MDSN still down try this:

http://www.svcutil.com/

 

Please give kudos if an advice helped to solve a specific problem (one solution is plenty for 1 thread), thanks!

Message 19 of 19
110000474593
in reply to: sszabo

Thank you very much sszabo. This week I'm going to try it with the config file you send me. I also will read about svcutil and WCFTestClient. I'll will let you know if it all works fine.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost