Accessing a web service from a dialog invoked by a commandbar button

Add-in Express™ Support Service
That's what is more important than anything else

Accessing a web service from a dialog invoked by a commandbar button
 
Kevin Roberts




Posts: 7
Joined: 2011-10-14
Using Visual Studio 2008 I created a sample project and added a Service Reference to it (http://footballpool.dataaccess.eu/data/info.wso?WSDL) which I named wsFootball. This is a web service that provides information and statistics about European football. For my example code I call the service to get a list of stadium names.

I created an ADX commandbar with a single button on it that displays a dialog. The dialog has a "Load Stadium Names" button on it and a listbox.


Public Class Dialog1

    Private Sub OK_Button_Click(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        Dim myService As New wsFootball.InfoSoapTypeClient
        Dim myStrings As List(Of String)
        myStrings = myService.StadiumNames

        ListBox1.DataSource = myStrings
    End Sub
End Class


The above code gives an error saying that "Type 'List' is not defined" and Visual Studio suggests that I import System.Collections.Generic. However, when I do import System.Collections.Generic I get warnings when I rebuild the solution:

Warning 1 Type library exporter warning processing 'ExampleForAdxSupport.wsFootball.ArrayOfString, ExampleForAdxSupport'. Warning: Type library exporter encountered a type that derives from a generic class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot be exposed for such types. Consider marking the type with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as the default interface to COM using the ComDefaultInterface attribute.



Warning 2 Type library exporter warning processing 'ExampleForAdxSupport.wsFootball.InfoSoapTypeClient, ExampleForAdxSupport'. Warning: Type library exporter encountered a type that derives from a generic class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot be exposed for such types. Consider marking the type with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as the default interface to COM using the ComDefaultInterface attribute.


If I ignore the warnings and try to use the toolbar, I get a runtime error when I click the button on the dialog to access the web service.

I struggled with this for a week before giving up on ADX and creating a toolbar directly with VB.NET code as a Shared Addin project in Visual Studio, in which case the above code works as expected. The commandbar button displays the dialog, the dialog accesses the web service and populates the listbox.

ADX makes it wonderfully easy to create the UI we want, but it seems that if we use ADX for the UI, we cannot access the web service.

I understand the problem has something to do with COM objects not recognizing generic types, but how do I get ADX to invoke a dialog in such a way that the dialog is able to access web services?

Regards.

Kevin
Posted 06 Nov, 2012 13:37:53 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello Kevin,

May I have your sample project for testing? If positive, please send it to the support email address, see readme.txt. Please make sure your email contains a link to this topic.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Nov, 2012 01:04:02 Top
Kevin Roberts




Posts: 7
Joined: 2011-10-14
Hello Andrei.

Sample applications have been sent as requested. One solution implements a toolbar without ADX and works. The second implements the toolbar *with* ADX and will not work due to the problems mentioned above.

Regards.

Kevin
Posted 07 Nov, 2012 10:09:06 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Kevin,

You sent the non-ADX project only. I suppose I know the cause of the issue however. You need to make sure of these things when reproducing the same in an Add-in Express based add-in:
1) the config file contents is correct
@) the config file gets delivered to the output folder of your project and then to the target machine; the best way to achieve this is to set the Copy To Output Folder property of the app.config item in the project to Copy Always
3) the name of the config file is mentioned in adxloader.dll.manifest

I suppose you missed #2 above.

If this doesn't help, please send me your other project for testing.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Nov, 2012 07:41:00 Top
Kevin Roberts




Posts: 7
Joined: 2011-10-14
Hello Andrei.

I sent the missing example project again.

I took your advice and set the app.config item to "Copy always" and ignored the two "Type library exporter" warning messages that still appear, and the application worked as expected.

Are the warning messages something I need to be concerned with? Can they be safely ignored, or it there something I can do to address them?

Regards.

Kevin
Posted 08 Nov, 2012 10:26:34 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Kevin,

In the ToolbarWithADX project, I set CopyToOutputDirectory=Always for the app.config item, set AdxCommandBar1.UseForRibbon = True in order to let the commandbar be shown in my Outlook 2010, registered the project and got it working.

Kevin Roberts writes:
However, when I do import System.Collections.Generic I get warnings when I rebuild the solution:


Try to declare that class as Friend, not Public.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 09 Nov, 2012 06:50:13 Top
Kevin Roberts




Posts: 7
Joined: 2011-10-14
I still get the error messages when I rebuild the solution regardless of whether the Dialog class is Public or Friend.
Posted 09 Nov, 2012 08:01:08 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
The warning message occurs because the type library exporter can see that class. You can set the visibility of the class to Private. Note that you can also ignore this warning because, anyway, these methods aren't exposed in the COM interface.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Nov, 2012 05:16:55 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Also, you can set ComVisible attribute for this class to False.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Nov, 2012 05:40:41 Top