有没有办法在不更改App.Config的情况下调用“更新服务参考”?

时间:2011-11-10 18:43:34

标签: wcf visual-studio-2010 app-config

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

这是我得到的例外:

  

下载时出错   的 'http://本地主机:8732 /为MyService / MEX'。

     

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

     

具有相同键的名为“endpoint”的子元素已存在于   相同的配置范围。集合元素必须是唯一的   相同的配置范围(例如,相同的application.config文件)。   重复的键值:   '合约类型: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。

2 个答案:

答案 0 :(得分:1)

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

p.s:如果您的客户是Silverlight

,请使用slsvcutil

答案 1 :(得分:1)

我的问题解决方案('更新服务参考'需要2秒... svcutil手动复制粘贴需要30秒,而且alt-tabs太多了):

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

它需要几秒钟,但仍然比使用svcutil更少的危险,说实话我只在IDE中添加服务失败时使用,我需要一些信息,对话框不会给我。

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