2011-12-22 58 views
0

我将WCF Servicereference添加到我的web应用程序中,以下条目已创建到我的web.config中。从Azure ServiceConfig调用WCF服务

<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服务?什么是实际entriess在ServiceConfig,以便我的应用程序将从服务配置读取我的WCF终点地址,而不是从web.config

回答

2

谢谢大家的帮助。

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

  1. 相关绑定,并在程序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); 
0

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

也许这也可以通过使用WebRole OnStart方法完成,但我不知道它是否是安全的在这一点上

+0

我一直在寻找内部ServiceConfiguration确切的配置项.cscfg,这样一旦包装在Azure中,我就可以dit ServiceConfiguration.cscfg并更改我的地址=“https:// staging。 NameVerification.com/Default/NameVerificationService.svc” – amazing 2012-01-05 04:21:45

0

如果我理解正确的修改web.config中,你只希望改变无需重新部署在Azure中运行的耗费服务的应用程序而使用哪些服务的端点?你不打算改变实际服务的端点,因为看起来这个服务在你的解决方案之外?

如果是这样,我想建议您使应用程序不依赖于web.config文件中指定的端点配置,而是在ServiceConfig文件中设置您的端点设置(无论您感觉到的任何名称 - 值对需要),并在构建代理以调用第三方端点时手动解析它们。这样你就可以完全控制你从web.config得到的东西(也许绑定配置仍然可以由web.config驱动)以及你从ServiceConfig(终点UrL等)得到的东西,并且是能够在稍后在ServiceConfig中切换端点而不重新部署和/或取消应用程序。

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

HTH