是否可以从 VS2010 插件刷新 WCF 服务引用?

发布于 2024-10-11 07:47:06 字数 442 浏览 2 评论 0原文

我想在 VS2010 插件中“模拟”右键单击/更新服务引用命令。我有一个对包含 (Silverlight...) 项目的引用,我知道服务引用的名称和服务的 url。
我发现了这个: http://dedjo .blogspot.com/2007/03/adding-web-references-to-your-vs.html,但它仅适用于asmx(它使用System.Web.Services而不是System.ServiceModel),不适用于wcf 。 是否有任何选择但是从代码中调用 svcutil ?如果是这样,怎么办? (我使用 svcutil 还是 slsvcutil?如何从插件内部调用它?)
谢谢

I want to "simulate" the Right click/Update service reference command in a VS2010 addin. I have a reference to the containing (Silverlight...) project, I know the name of the service reference and the url of the service.
I've found this: http://dedjo.blogspot.com/2007/03/adding-web-references-to-your-vs.html , but it only works for asmx (it uses System.Web.Services instead of System.ServiceModel), not wcf.
Is there any choice but call svcutil from code? if so, how? (do I use svcutil or slsvcutil? How do I call it from inside the addin?)
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心凉 2024-10-18 07:47:06

我相信 Visual Studio 的命令是“Project.UpdateServiceReference”。所以我想你可以尝试选择你感兴趣的节点,然后运行这个命令,如下所示:

envDTE.Windows.Item(vsWindowKindSolutionExplorer).Activate();
envDTE.ActiveWindow.Object.GetItem(@"MyProject\Service References\Proxy").Select(vsUISelectionType.vsUISelectionTypeSelect);
envDTE.ExecuteCommand("Project.UpdateServiceReference");

I believe the visual studio command for this is "Project.UpdateServiceReference". So I guess you can try to select the node you're interested in, and run this command, like this:

envDTE.Windows.Item(vsWindowKindSolutionExplorer).Activate();
envDTE.ActiveWindow.Object.GetItem(@"MyProject\Service References\Proxy").Select(vsUISelectionType.vsUISelectionTypeSelect);
envDTE.ExecuteCommand("Project.UpdateServiceReference");
○闲身 2024-10-18 07:47:06

如果您正在寻找更具编程性的方法来执行此操作,您可以执行以下操作。此方法不需要使用 DTE 自动化层,该层将更改用户的选择并执行命令。请注意,这是在带有 IServiceProvider 的 VSPackage 上下文中,以便它可以获取核心 Visual Studio 接口的实例等...

您也可以从外接程序中执行此操作,但是 您需要获取 IServiceProvider 并添加对(至少) Microsoft.VisualStudio.Shell.Interop.dll 和 Microsoft.VisualStudio.WCFReference.Interop。这些二进制文件的参考程序集可在 Visual Studio 2010 SDK 中找到。

IVsSolution solution = GetService(typeof(SVsSolution)) as IVsSolution;
if (solution != null)
{
    IVsHierarchy solutionHierarchy = solution as IVsHierarchy;
    if (null != solutionHierarchy)
    {
        IEnumHierarchies enumHierarchies;
        Guid nullGuid = Guid.Empty;

        ErrorHandler.ThrowOnFailure(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLINSOLUTION, ref nullGuid, out enumHierarchies));
        if (enumHierarchies != null)
        {
            uint fetched;
            IVsHierarchy[] hierarchies = new IVsHierarchy[1];
            IVsWCFReferenceManagerFactory wcfReferenceManagerFactory = GetService(typeof(SVsWCFReferenceManagerFactory)) as IVsWCFReferenceManagerFactory;
            if (wcfReferenceManagerFactory != null)
            {
                while (enumHierarchies.Next(1, hierarchies, out fetched) == 0 && fetched == 1)
                {
                    if (wcfReferenceManagerFactory.IsReferenceManagerSupported(hierarchies[0]) == 1)
                    {
                        IVsWCFReferenceManager referenceManager = wcfReferenceManagerFactory.GetReferenceManager(hierarchies[0]);
                        var referenceGroupCollection = referenceManager.GetReferenceGroupCollection();
                        referenceGroupCollection.UpdateAll(null);
                    }
                }
            }
        }
    }
}

我还建议查看 Visual Studio 2010 SDK 的 WCF 服务使用工具示例

If you're looking for the more programmatic way to do this, you can do something like the following. This approach does not require using the DTE automation layer which will change the user's selection and execute a command. Note that this is within the context of a VSPackage with an IServiceProvider so that it can get instances to the core Visual Studio interfaces, etc...

You may also be able to do this from within an Addin, but you'd need to get an IServiceProvider and add references to (at least) Microsoft.VisualStudio.Shell.Interop.dll and Microsoft.VisualStudio.WCFReference.Interop. Reference assemblies for these binaries are available in the Visual Studio 2010 SDK.

IVsSolution solution = GetService(typeof(SVsSolution)) as IVsSolution;
if (solution != null)
{
    IVsHierarchy solutionHierarchy = solution as IVsHierarchy;
    if (null != solutionHierarchy)
    {
        IEnumHierarchies enumHierarchies;
        Guid nullGuid = Guid.Empty;

        ErrorHandler.ThrowOnFailure(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLINSOLUTION, ref nullGuid, out enumHierarchies));
        if (enumHierarchies != null)
        {
            uint fetched;
            IVsHierarchy[] hierarchies = new IVsHierarchy[1];
            IVsWCFReferenceManagerFactory wcfReferenceManagerFactory = GetService(typeof(SVsWCFReferenceManagerFactory)) as IVsWCFReferenceManagerFactory;
            if (wcfReferenceManagerFactory != null)
            {
                while (enumHierarchies.Next(1, hierarchies, out fetched) == 0 && fetched == 1)
                {
                    if (wcfReferenceManagerFactory.IsReferenceManagerSupported(hierarchies[0]) == 1)
                    {
                        IVsWCFReferenceManager referenceManager = wcfReferenceManagerFactory.GetReferenceManager(hierarchies[0]);
                        var referenceGroupCollection = referenceManager.GetReferenceGroupCollection();
                        referenceGroupCollection.UpdateAll(null);
                    }
                }
            }
        }
    }
}

I'd also recommend looking at the WCF Service Consumption Tools samples for the Visual Studio 2010 SDK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文