1

Currently baseAddress is fixed in the app.config file for both service and client

App.Config for both service and client

<host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/service" />
      </baseAddresses>
    </host>

Is it possible to it programmatically? Like

baseAddress = txtbaseAddress.Text;

Or any?

4

2 回答 2

0

您不能使用 ServiceHost 更新基地址,因为它是只读的。您必须将一组 baseAddress 传递给 ServiceHost 构造函数,否则您必须使用配置文件。

请参考以下链接

  1. MSDN

  2. MSDN 博客

<system.serviceModel>
  <serviceHostingEnvironment>
     <baseAddressPrefixFilters>
        <add prefix=”net.tcp://test1.fabrikam.com:8000”/>
        <add prefix=”http://test2.fabrikam.com:9000”/>
    </baseAddressPrefixFilters>
  </serviceHostingEnvironment>
</system.serviceModel>
于 2013-05-04T13:00:09.293 回答
0

虽然这有点晚了,但它可能对其他人有用。

使用基于 ServiceHostFactoryBase 的自定义服务主机,如下所示: Service Host Factory Base

实施示例:实施自定义服务主机

此外,ServiceHostBase 类是抽象的,可用于创建自定义 ServiceHost。

于 2015-07-08T15:33:12.697 回答