[英]Calling WCF service from Azure ServiceConfig
我將WCF Servicereference添加到我的webapplication中,以下條目已創建到我的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中的實際內容是什么,以便我的應用程序將從Service配置而不是web.config中讀取我的WCF端點地址
謝謝大家的幫助 。
我找到了解決這個問題的方法。
<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 );
考慮使用啟動任務和控制台實用程序從RoleEnvironment讀取配置並手動(或使用ServiceManager)更新web.config。 另一種選擇是在顯式服務創建之前使用Service Factory並讀取角色配置。
也許它也可以通過使用WebRole OnStart方法來完成,但我不確定此時是否可以安全地修改web.config
如果我理解正確,您只需要更改您使用的服務的端點,而無需重新部署在Azure中運行的服務消耗應用程序? 您不希望更改實際服務的終點,因為此服務似乎是您的解決方案的外部服務?
如果是這樣,我建議您使應用程序不依賴於web.config文件中指定的端點配置,而是在ServiceConfig文件中設置端點設置(無論您認為需要什么名稱 - 值對)和在構建代理時手動解析它們以調用第三方端點。 通過這種方式,您可以完全控制從web.config獲得的內容(也許綁定配置仍然可以由web.config驅動)以及從ServiceConfig(終點UrL等)獲得的內容能夠在ServiceConfig中稍后切換端點,無需重新部署和/或關閉應用程序。
如果您在Azure(真實或模擬器)下運行以便從ServiceConfig中讀取,則需要檢查RoleEnvironment。
HTH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.