有没有办法调用“更新服务参考”?不改变App.Config?

发布于 2024-12-14 23:31:34 字数 6644 浏览 1 评论 0原文

好的,我管理自己的 App.Config。我不需要向导来帮我做这件事,非常感谢。它放入我的 App.Config 中的代码是冗长的垃圾。我能够编写自己的 WCF 端点和绑定。我只是希望 Visual Studio 2010 能够做它最擅长的事情:代码生成。只需给我服务器和数据合约代码即可!有什么办法可以关掉这个功能吗?有没有办法在 VS 不更改 App.Config 的情况下调用“更新服务引用”?这非常令人沮丧。现在它给了我一个例外,除非我从我的 App.Config 中完全删除所有端点节点。

这是我得到的例外:

下载时出错 'http://localhost:8732/MyService/mex'。

请求失败,HTTP 状态为 400:错误请求。

具有相同键的名为“endpoint”的子元素已存在于 相同的配置范围。集合元素在内部必须是唯一的 相同的配置范围(例如相同的application.config文件)。 重复键值: 'contractType:Web.DataService.MyService.IMyService;名称:MyService.Live'。 (C:\ProjectPath\App.config 第 152 行)

这是我的 App.Config:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="Binding.Debug" maxReceivedMessageSize="2147483647">
            </binding>
            <binding name="Binding.Secure" maxReceivedMessageSize="2147483647">
                <security mode="Transport">
                    <transport clientCredentialType="None"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <!-- Debug client endpoints -->

        <endpoint name="MyService.Debug"
                  contract="Web.DataService.MyService.IMyService" 
                  address="http://localhost:8732/MyService"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />
        <endpoint name="MyService1.Debug"
                  contract="Web.DataService.MyService1.IMyService1" 
                  address="http://localhost:8732/MyService1"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />
        <endpoint name="MyService2.Debug"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="http://localhost:8732/MyService2"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />
        <endpoint name="MyService3.Debug"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="http://localhost:8732/MyService3"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />

        <!-- Local client endpoints -->

        <endpoint name="MyService.Local"
                  contract="Web.DataService.MyService.IMyService" 
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService1.Local"
                  contract="Web.DataService.MyService1.IMyService1" 
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService1.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService2.Local"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService2.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService3.Local"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService3.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />

        <!-- Beta client endpoints -->

        <endpoint name="MyService.Beta"
                  contract="Web.DataService.MyService.IMyService"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService1.Beta"
                  contract="Web.DataService.MyService1.IMyService1"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService1.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService2.Beta"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService2.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService3.Beta"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService3.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />

        <!-- Live client endpoints -->

        <endpoint name="MyService.Live"
                  contract="Web.DataService.MyService.IMyService"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService1.Live"
                  contract="Web.DataService.MyService1.IMyService1"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService1.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService2.Live"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService2.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService3.Live"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService3.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
    </client>
</system.serviceModel>

这非常令人沮丧!

编辑:

我已经弄清楚了我遇到的异常。我有两次 MyService2.Live。我修复了这个问题,不再出现异常。我仍然想知道是否可以阻止 VS10 更改我的 App.Config。

Ok, I manage my own App.Config. I don't need a wizard to do it for me, thank you very much. And the code that it puts in my App.Config is verbose garbage. I am capable of writing my own WCF endpoints and bindings. I just want Visual Studio 2010 to do what it is best at doing: code generation. Just give me the server and data-contract code! Is there any way to turn this off? Is there a way to call 'Update Service Reference' without VS changing the App.Config? Its very frustrating. Now it gives me an exception unless I completely delete all of the endpoint nodes from my App.Config.

This is the exception that I get:

There was an error downloading
'http://localhost:8732/MyService/mex'.

The request failed with HTTP status 400: Bad Request.

A child element named 'endpoint' with same key already exists at the
same configuration scope. Collection elements must be unique within
the same configuration scope (e.g. the same application.config file).
Duplicate key value:
'contractType:Web.DataService.MyService.IMyService;name:MyService.Live'.
(C:\ProjectPath\App.config line 152)

And here is my App.Config:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="Binding.Debug" maxReceivedMessageSize="2147483647">
            </binding>
            <binding name="Binding.Secure" maxReceivedMessageSize="2147483647">
                <security mode="Transport">
                    <transport clientCredentialType="None"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <!-- Debug client endpoints -->

        <endpoint name="MyService.Debug"
                  contract="Web.DataService.MyService.IMyService" 
                  address="http://localhost:8732/MyService"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />
        <endpoint name="MyService1.Debug"
                  contract="Web.DataService.MyService1.IMyService1" 
                  address="http://localhost:8732/MyService1"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />
        <endpoint name="MyService2.Debug"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="http://localhost:8732/MyService2"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />
        <endpoint name="MyService3.Debug"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="http://localhost:8732/MyService3"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Debug"
                  />

        <!-- Local client endpoints -->

        <endpoint name="MyService.Local"
                  contract="Web.DataService.MyService.IMyService" 
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService1.Local"
                  contract="Web.DataService.MyService1.IMyService1" 
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService1.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService2.Local"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService2.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService3.Local"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService3.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />

        <!-- Beta client endpoints -->

        <endpoint name="MyService.Beta"
                  contract="Web.DataService.MyService.IMyService"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService1.Beta"
                  contract="Web.DataService.MyService1.IMyService1"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService1.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService2.Beta"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService2.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService3.Beta"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService3.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />

        <!-- Live client endpoints -->

        <endpoint name="MyService.Live"
                  contract="Web.DataService.MyService.IMyService"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService1.Live"
                  contract="Web.DataService.MyService1.IMyService1"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService1.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService2.Live"
                  contract="Web.DataService.MyService2.IMyService2"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService2.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
        <endpoint name="MyService3.Live"
                  contract="Web.DataService.MyService3.IMyService3"
                  address="https://www.mydomain.com/MyVirtualDirectory/MyService3.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="Binding.Secure"
                  />
    </client>
</system.serviceModel>

This is very frustrating!

Edits:

I've figured out the exception that I was getting. I had MyService2.Live twice. I fixed this and no longer get the exception. I'd still like to know if I can keep VS10 from changing my App.Config.

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

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

发布评论

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

评论(2

身边 2024-12-21 23:31:34

您可以使用 svcutil 工具生成文件并手动将它们与你修改过的那些。

ps:如果您的客户端使用 slsvcutil是银光

You could use the svcutil tool to generate the files and manually merge them with the ones you have modified.

p.s: use slsvcutil if your client is Silverlight

早乙女 2024-12-21 23:31:34

我的问题解决方案(“更新服务引用”需要 2 秒...手动复制粘贴的 svcutil 需要 30 秒并且 alt-tabs 太多):

  • 如果您使用源代码控制(例如 TFS)...检查更新之前的 app 或 web.config。然后运行“更新服务参考”。这将自动检查配置文件。更新后,只需从源代码管理中“撤消签出”即可恢复原始代码,但生成的参考代码将被更新。
  • 如果不在源代码管理上:打开应用程序或 web.config 文件,选择所有文本 (ctrl+a),复制 (ctrl+c),更新服务引用,再次选择配置文件中的所有文本 (ctrl+a),粘贴(ctrl+v)。

它需要多几秒钟的时间,但仍然比使用 svcutil 危险要小,说实话,我只在 IDE 中添加服务失败并且我需要一些对话框无法提供的信息时才使用它。

旁注:如果您要添加服务,您当然应该为新服务手动添加正确的绑定和端点。

My solutions for the problem ('Update service reference' takes 2 seconds ... svcutil with manual copy paste takes 30 seconds and too much alt-tabs):

  • If you're on source control (e.g. TFS) ... check in the app or web.config before updating. Then run 'Update service reference'. This will automatically check out the config file. After the update, just 'Undo checkout' from source control should put the original one back, but the generated reference code will be updated.
  • If not on source control: Open the app or web.config file, select all text (ctrl+a), copy (ctrl+c), update service reference, select all text in the config file again (ctrl+a), paste (ctrl+v).

It takes a few seconds longer, but still less of a hazard than using svcutil, which to be honest I only use when adding a service in the IDE fails and I need some info the dialog won't give me.

Sidenote: If you're adding a service, you should manually add the correct bindings and endpoints for your new service ofcourse.

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