views:

178

answers:

0

Info: Visual Studio 2010, C#

I am looking at the following functionality via a Visual Studio Add-in

  1. User has a Class Project and clicks a button (This bit is fine)
  2. WCF Project is automatically created in current solution (This bit is fine)
  3. Service Reference is added to the current Project

I can create a working WCF Project and if I manually add a service reference using the discovery option then I can add it fine. I want to able to do this programatically and then be able to get the methods from the WCF Services interface, just like the Service Dialog gives you.

I am able to show the dialog but can't get the Interface methods

  private static void Reference2(IVsHierarchy hierarchy)
    {
        //Get the global IVsAddWebReferenceDlg3 service.
        IVsAddWebReferenceDlg3 dlgService =
            (IVsAddWebReferenceDlg3)Package.GetGlobalService(typeof(SVsAddWebReferenceDlg3));
        IVsAddWebReferenceResult result; //Result of the operation.

        IVsDiscoveryService discoveryService = Package.GetGlobalService(typeof(SVsDiscoveryService)) as IVsDiscoveryService;
        IDiscoverySession discoverySession = null;

        if (discoveryService != null)
        {
            discoveryService.CreateDiscoverySession(out discoverySession);
        }

        try
        {
            int fCancelled;

            //Invoke the "Add Service Reference(ASR)" dialog by calling the following method. This
            // returns the result when user clicks OK in the dialog after discovering the service.
            dlgService.ShowAddWebReferenceDialog(
                hierarchy, //Associated Project
                discoverySession, //DiscoverySession
                ServiceReferenceType.SRT_WCFReference,
                //Type of service reference to create (old asmx or new WCF service reference)
                null, //Title of the dialog (null for default)
                null, //Must be null
                null, //Reference.Config file (normally null)
                out result, //Result
                out fCancelled); //Boolean value indicating if the user clicked cancel
            //Check if user cancelled or clicked OK.
            if (fCancelled != 0)
            {
            }
            else
            {
                //Save the result we obtained from the above method, which includes all the information
                //necessary for the service to add the given service reference to the project, but that
                //does not actually occur until/unless you call Save().
                IVsWCFReferenceGroup x = result.Save();
            }
        }
        catch (Exception ex)
        {
            Log.Write(String.Format(CultureInfo.InvariantCulture, "Uh oh: {0}", ex));
        }
        return;
    }

Documentation is very thin on the ground around this area, it is either because I am somewhere I shouldn't be in the API or it's seldom used. Any ideas would be fantastic.