【问题标题】:Programmatically edit the end point of a web service以编程方式编辑 Web 服务的端点
【发布时间】:2010-08-19 13:43:32
【问题描述】:

有没有办法以编程方式更改 Web 服务的 <endpoint address="..." /> 值?在我的 app.config 文件中,我有以下代码:

<system.serviceModel>
   <bindings>
       ...
   </bindings>
   <client>
     <endpoint address="http://dev.remotedomain.com/WebServices/WebService.asmx"
         binding="basicHttpBinding" bindingConfiguration="InboxServiceSoap"
         contract="InboxServiceSoap"
         name="InboxServiceSoap" />
   </client>
</system.serviceModel>

我希望能够改变

address="http://dev.remotedomain.com/WebServices/WebService.asmx"

address="http://mymachine/WebServices/WebService.asmx"

在代码中。这在 .NET 中是否可能以编程方式实现?

【问题讨论】:

    标签: .net web-services configuration console-application


    【解决方案1】:

    您可以使用类似于以下的代码:

    Dim 服务作为新的 XXXXXClient service.Endpoint.Address = 新的 EndpointAddress(myUrl)

    【讨论】:

    • 这可行,但让我怀疑。添加 WCF 服务引用后,有六个项目文件引用了服务 URL。然后我将服务移动到不同的 URL,添加这行代码,一切正常。好像不应该编译???
    • @nuander 编译很好,只是字符串不同。只要不同的 URL 遵循相同的协议和格式,也没有运行时问题。
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多