2011-12-22 32 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