Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Call webservices from Inventor Addin

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
FRPT1257
674 Views, 11 Replies

Call webservices from Inventor Addin

I am using some webservices in my Inventor Addin (as previous in Office Addin), and I am using App.config to define webservices path.

 

The Inventor addin is not assuming the webservices paths defined in App.config.

 

In Office addin worked perfect.

 

What could be?

 

Thanks & Regards,

Rui

11 REPLIES 11
Message 2 of 12
philippe.leefsma
in reply to: FRPT1257

I'm not an expert in Office add-ins, but a simple way I'm solving that with Inventor add-ins is to have an addin.config file located in the same directory than my add-in dll, then I load the config at runtime.

 

Here is an example where I instanciate a WPF service from my add-in:

 

FileInfo fi = new FileInfo(
    System.Reflection.Assembly.GetExecutingAssembly().Location);

string configPath = fi.DirectoryName + "\\" + "addin.config";

Configuration config = 
    ConfigurationManager.OpenMappedExeConfiguration(
        new ExeConfigurationFileMap { ExeConfigFilename = configPath },
        ConfigurationUserLevel.None);

ConfigurationChannelFactory<IAdnViewerConsoleSrv> channelFactory =
    new ConfigurationChannelFactory<IAdnViewerConsoleSrv>(
        "WCFClientEndpoint", 
        config, 
        null);

_serviceClient = channelFactory.CreateChannel();

Hope that helps,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 12
FRPT1257
in reply to: philippe.leefsma

 

I have an “App.config” in my project that when compiled generates a similar “ApplicationAddin.dll.config” file located in the same directory than my add-in dll.

 

In Office addin application (and for all other .Net applications) automatically load from this config file.

 

Thanks & Regards,

Rui

Message 4 of 12
philippe.leefsma
in reply to: FRPT1257

It's different in Inventor, you will most likely need to "manually" load your config file as I illustrated above...

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 5 of 12
FRPT1257
in reply to: philippe.leefsma

What is the "IAdnViewerConsoleSrv" and the "_serviceClient".

 

I do not call any webservice directly from my Inventor addin. In Inventor Addin I created some .Net Dlls with common code and webservices are called from that Dlls.

 

I created these Dlls because the code inside is used from all addins, Office, Inventor, ...

 

Message 6 of 12
philippe.leefsma
in reply to: FRPT1257

Those are my WCF interface and client, I use them to perfom the web service calls. It's very unclear what you are doing, so please provide further information... What are you using to call the web services? Most likely you will need a way to initialize your service client from providing a path to the config file. If you cannot do that, you may need to review your approach.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 7 of 12
FRPT1257
in reply to: philippe.leefsma

I have some Dlls and that Dlls make some calls of webservices. Each of that that dll have an App.config where it is defined the path for the webservices.

Sample code of the App.config:

 

<eGrouWS.Properties.Settings>
  <setting name="eGrouWS_WSDocument_ws_Document" serializeAs="String">
   <value>http://localhost:4451/ws_Document.asmx</value>
  </setting>
</eGrouWS.Properties.Settings>

 

 

These dlls are added to my addins, and in each addin I have an App.config where I redefine the url for the webservices called in dlls. For example:

       

<eGrouWS.Properties.Settings>
  <setting name="eGrouWS_WSDocument_ws_Document" serializeAs="String">
    <value>http://roliveira/ws_Document.asmx</value>
  </setting>
</eGrouWS.Properties.Settings>

 

 

This works perfect for the Office addins and for all other .Net projects that use these same dlls.

Here a sample code of calling a webservice in dlls:

 

ws_Document iws_docm = new ws_Document();
ids_docm = iws_docm.m_GetDocument(is_codValtId, is_sessionKey, is_codDocmId);

 

 

Message 8 of 12
philippe.leefsma
in reply to: FRPT1257

Sorry I don't have experience with ASMX web services, this is the "old" way to deal with web services, if you have the opportunity you should migrate to WCF.

 

The samples I provided are based on WCF and I don't have any issue to use my services from an Inventor add-in.

 

I think the issue might be your services are looking for the config file in the exe folder, which is most likely different from the addin dll folder, did you try to place the config file in the Inventor.exe folder?

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 9 of 12
FRPT1257
in reply to: philippe.leefsma

Spoiler
 

I have tried to put config file in Inventor.exe folder without success.

 

Message 10 of 12
FRPT1257
in reply to: FRPT1257

 

I put my "eGrouWSInventorAddin.dll.config" in Inventor.exe but without success

Message 11 of 12
FarrenYoung
in reply to: FRPT1257

Try copying your settings to the 'Inventor.exe.config' file in the bin folder. This isn't the ideal solution as if you mess this file up Inventor will not load. Definitely back the config file up so that you don't have to reinstall Inventor. As Philippe said you should be able to specify the configuration file to use, but if for some reason that's not working the Inventor config file should do the trick, just ensure you copy all the required sections.
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 12 of 12
rjay75
in reply to: FRPT1257

This has to do with the mechanisms that are loading the dll and activating the add ins. Inventor most likely is not loading it's addin's in the exact same fashion Office loads it's addins. You basically need a way to point your addin to the correct configuration file.  You can explictly load the correct configuration file and use the value to initialize the webservice. But it depends on how your dll that uses the webservice looks up the value from the configuration.

 

See this link from Stack Overflow that details this problem and has a solution. This may work but may have unknown side effects.

 

I think the best method for your case since you will be using the DLL from multiple types of addins is to have the dll explictly load its own config file or add a way to pass the needed value to the dll when you use it.

 

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

Post to forums  

Autodesk Design & Make Report