0

我将 WCF 服务引用添加到我的 web 应用程序中,以下条目被创建到我的 web.config 中。

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_INameVerification" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="https://int. NameVerification.com/Default/NameVerificationService.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_INameVerification"
    contract="NameVerificationService.INameVerification"
    name="WSHttpBinding_INameVerification" />
</client>

现在我计划将我的应用程序托管到 Azure 云平台。一旦我在云上托管我的应用程序,我希望能够随时更改我的端点,即。

<endpoint address=”https://int. NameVerification.com/Default/NameVerificationService.svc” 
   binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_INameVerification"
    contract="NameVerificationService.INameVerification"
    name="WSHttpBinding_INameVerification" />

如何从 SericeConfig 将此调用添加到我的 WCF 服务?ServiceConfig 中的实际条目是什么,以便我的应用程序将从服务配置而不是从 web.config 读取我的 WCF 端点地址

4

3 回答 3

2

谢谢大家的帮助 。

我找到了解决这个问题的方法。

  1. 在程序中关联 binding 和 serviceaddress,然后在 Serviceconfig 中添加设置
  2. 已添加 ServiceConfig 条目
<Setting name="myServiceAddressUrl"
    value="https://int.
    NameVerification.com/Default/NameVerificationService.svc" />
    WSHttpBinding binding = new WSHttpBinding();
    binding.Name = "WSHttpBinding_INameServiceVerification";
    binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
    binding.ReliableSession.Enabled = false;
    binding.TransactionFlow = false;
    binding.Security.Mode = SecurityMode.Transport;
    binding.Security.Message.ClientCredentialType = 
        MessageCredentialType.Windows;

    string myServiceAddressUrl = 
        RoleEnvironmentWrapper.GetConfigurationSettingValue(
           "AdderssServiceURL.svc");
    EndpointAddress myService = new EndpointAddress(myServiceAddressUrl);

    NameVerificationClient verificationClient = 
        new NameVerificationClient(binding, myService );
于 2012-01-13T18:15:03.937 回答
0

考虑使用带有控制台实用程序的启动任务从 RoleEnvironment 读取配置并手动(或使用 ServiceManager)更新您的 web.config。另一种选择是在显式创建服务之前使用服务工厂并读取角色配置。

可能也可以通过使用 WebRole OnStart 方法来完成,但我不确定此时修改 web.config 是否安全

于 2011-12-26T10:35:02.367 回答
0

如果我理解正确,您只是想更改您使用的服务的端点,而不重新部署在 Azure 中运行的服务使用应用程序?您不希望更改实际服务的端点,因为该服务似乎在您的解决方案之外?

如果是这样,我建议您使您的应用程序不依赖于 web.config 文件中指定的端点配置,而是在 ServiceConfig 文件中检测您的端点设置(在您认为需要的任何名称-值对中)和在构建代理以调用您的第 3 方端点时手动解析它们。这样,您将完全控制从 web.config 获得的内容(也许绑定配置仍然可以由 web.config 驱动)以及从 ServiceConfig 获得的内容(端点 UrL 等)并且是能够稍后在 ServiceConfig 中切换端点,而无需重新部署和/或关闭您的应用程序。

如果您在 Azure(真实或模拟器)下运行,则需要检查 RoleEnvironment 才能从 ServiceConfig 中读取。

高温高压

于 2011-12-26T19:14:10.163 回答