none
客户端和服务端的配置文件为什么不能使用类似web.debug.config/web.release.config的方式 RRS feed

  • 问题

  • 我创建的WCF项目和Windows Form项目需要调用WCF项目或者WebApi项目,由于调试环境和正式环境的http路径不一样,导致每次调试或发布时需要更改路径,有什么办法可以在发布时自动更新地址,类似网页程序的web.debug.config和web.release.config。我参照网页程序的.csproj试过更改,但会导致其他错误。
    2019年11月29日 6:10

全部回复

  •      

    Hi,
    如果你通过添加服务引用的方式调用WCF,你一样可以在配置文件中以替换webconfig节点的方式更改这些配置,
    假设生成的配置如下。
    Web.config

    <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IService" />
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:21011/" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
                    name="BasicHttpBinding_IService" />
            </client>
    </system.serviceModel>
    我们可以在web.release.config替换生成的终结点地址。 
    Web.Release.config
        <system.serviceModel xdt:Transform="Replace">
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IService" />
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://MyServer:21011/" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
                    name="BasicHttpBinding_IService" />
            </client>
    </system.serviceModel>

    For Winform App.config.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/708faeb9-b4d5-49f1-971d-d4c5ad22fd59/appconfig-for-release-and-another-for-debug?forum=csharpgeneral

    如果您对Visual Studio 或Microsoft Azure相关产品感兴趣,请点击此链接,或扫描以下二维码注册获取相关信息。

    https://i.stack.imgur.com/b3pWC.jpg

    Abraham



    2019年12月2日 10:26