从数据库配置服务引用URL值

时间:2018-02-04 08:33:12

标签: .net wcf configure endpoint service-reference

我正在引用一个WCF服务,这是我在Web.config中的配置:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://tempserver/Service/v1/Service.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="UserService.IService" name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>

我的问题是:有没有办法在数据库中配置端点地址? 我可以在数据库中存储“http://tempserver/Service/v1/Service.svc”吗?

1 个答案:

答案 0 :(得分:0)

在您编写托管服务代码的课程中,您可以进行以下配置。

@Produces
@Dependent //choose desired scope, or none and it will be dependeny
// you can also add qualifiers, optional
public Random produceRandom() {
  return new Random();
}

其中uri在代码中是硬编码的,您可以从DB中提取此值。